I've wrote a kind of picture-resize-script (uses GD). My site is hosted by one.com, I don't have full control over the webbserver wich makes debugging pretty limited.
This is the case: The script looks though a folder with pictures in it, randomizes four pictures and creates small thumbnail of them. It then merges these four thumbnail to one picture. This script works fine on most folders, but some makes the script bail out, leaving a fatal error message saying I use more than 16 MB of memory. This is the piece of code where it happens:
//Resize and merge
$im_final = imagecreatetruecolor(162, 122);
imagefill($im_final, 2, 2, imagecolorallocate($im_final, 255, 255, 255));
$im_src = imagecreatefromjpeg("../pics/pic_archive/".$dir."/".$files[1][$arr[0]]) or die("Could not open file.");
imagecopyresampled($im_final, $im_src, 0, 0, 0, 0, $width, $height, imagesx($im_src), imagesy($im_src));
imagedestroy($im_src);
/*$im_src = imagecreatefromjpeg("../pics/pic_archive/".$dir."/".$files[1][$arr[1]]) or die("Could not open file.");
imagecopyresampled($im_final, $im_src, 82, 0, 0, 0, $width, $height, imagesx($im_src), imagesy($im_src));
imagedestroy($im_src);
$im_src = imagecreatefromjpeg("../pics/pic_archive/".$dir."/".$files[1][$arr[2]]) or die("Could not open file.");
imagecopyresampled($im_final, $im_src, 0, 62, 0, 0, $width, $height, imagesx($im_src), imagesy($im_src));
*/
$im_src = imagecreatefromjpeg("../pics/pic_archive/".$dir."/".$files[1][$arr[3]]) or die("Could not open file.");
imagecopyresampled($im_final, $im_src, 82, 62, 0, 0, $width, $height, imagesx($im_src), imagesy($im_src));
imagedestroy($im_src);
return $im_final;
As you can see some lines are commented out and just two thumbnails are created instead of four. This makes the script use less than 16M. I've tried using imagedestroy($im_src) to free up memory but it makes no difference at all.
The pictures are taken with a normal digital camera at 2M and use normal JPEG compression. Four of them are about 1M in total size.
What makes the script hit the roof like that?