View Full Version : Help with GD for PHP

07-16-2007, 10:25 PM
hello, I am trying to get a small php script to run that generates a jpg however everytime i run it i receive an internal server error(500).

I have tested it on 2 other servers and it runs fine, but on this one specific server it errs out. using php5 with gd2.0 compiled. any suggestions where the problem may be?


$ts_start_g = microtime(1);

$a_photo_paths = array("DSC02275.JPG","DSC02275.JPG","DSC02275.JPG","DSC02275.JPG","DSC02275.JPG","DSC02275.JPG","DSC02275.JPG","DSC02275.JPG","DSC02275.JPG","DSC02275.JPG");

$a_records = array();
foreach($a_photo_paths as $i => $s_path) {
$ts_start = microtime(1);
$img_source = imagecreatefromjpeg($s_path);
$img_print = imagecreatetruecolor(500, 375);
imagecopyresampled($img_print, $img_source, 0, 0, 0, 0, 500, 375, 1632, 1224);
imagejpeg($img_print, "resized/".$s_path, 85);
$a_records[] = round(microtime(1) - $ts_start, 5)." -- ".$s_path;
if($i >= 9) break;


07-16-2007, 10:44 PM
If the code works fine on other servers then the problem isnt in your code. Do you have any kind of support with your hosting?

07-16-2007, 11:08 PM
Yes. What is it that they should be looking for to determine what is causing the issue? I know GD works on the server because I use it to generate captcha images with security codes and random letters/numbers in the image.

07-16-2007, 11:12 PM
what I would do is just send them the script, explain that it works on other servers you've tried it on and ask why it doesnt work on their server and then what can they do to make it work - you are their customer after all.

07-16-2007, 11:25 PM
Not sure if this will help...but If GD is installed on that particular server, it could will be something to do with the amount of memory allocated.

try adding the following at the top of page


07-16-2007, 11:39 PM
memory limit shouldnt cause an internal server error. It should just give you a nice little message saying you've exceeded the memory limit... then again that code shouldnt cause an internal server error either.

07-17-2007, 12:31 AM
thanks everyone. the post about memory limit gave me an idea.

it had to do with CPU time allowed to process the requests.

currently there were 10 images in the array causing an internal server error. when I removed them and left 1 image in the array the script ran fine and returned:

Process took 0.92 seconds.

tried it with up to 9 images and all was good until the 10th image which exceeded 10 seconds of CPU time.

so it appears as though host does not allow the script to process longer than roughly 10-12 seconds before causing an error