I have written a image database for a photojournalist in PHP + MySQL. All worked out fine, but after exceeding 600 or 700 images, a Script started to make Problems. The Script is used to browse the Photo directory for new Pictures, resizes them to a small preview, and a medium preview which also gets a copyright stamp there. After resizing 8 Images the Script stops for two Seconds, and starts over again looking for the next 8 new uploads.
I am not sure if the Provider has changed anything, or it is the Scripts fault - after the last upload of Images i get the Error code: Fatal error: Allowed memory size of 8388608 bytes exhausted at (null):0 (tried to allocate 6396 bytes) in /home/www/web671/html/cms/resize.php on line 51
The Line Number differs sometimes
Beside asking the Provider tomorrow, i would like to optimize the Code anyway, because using 8 Megs seems quite a lot to me. Can anyone take a look at the Code Snipplet, and give me a hint how i could get this done? I've tried a few Tweaks (like resizing just 1 or 2 images per reload...)
Thanks for reading, Greetings - and i would be glad to get some help
kami / LSArcher
The Essential Part of the Script (without the reload action, just it's break)
chdir("/home/www/web671/html/foto/images/fotos/");
$a = "0";
$mydir = getcwd();
$hdl = opendir($mydir);
while ($file = readdir($hdl))
{
if (!eregi("thumb." , $file) && !eregi("mediumthumb." , $file) && eregi(".jpg*" , $file) && !file_exists("thumb$file") && !file_exists("mediumthumb$file"))
{
$a++;
if ($a > 8)
{ break; }
printf ("<font><span class='bold'>$file<br></span></font>");
$imageInfo = getimagesize($file);
$width = $imageInfo[0];
$height = $imageInfo[1];
$width = round($width/18);
$height = round($height/18);
$im = ImageCreateFromjpeg($file);
$im_neu=ImageCreatetruecolor($width,$height);
ImageCopyResized($im_neu,$im,0,0,0,0, $width,$height,ImageSX($im),ImageSY($im));
Imagejpeg($im_neu, "/home/www/web671/html/foto/images/fotos/thumb$file");
printf("<font><span class='bold'>thumb$file</span> in der größe $width x $height wurde erzeugt<br></font>");
ImageDestroy($im);
ImageDestroy($im_neu);
$imageInfo = getimagesize($file);
if(!isset($s)) $s=15;
$width = $imageInfo[0];
$height = $imageInfo[1];
$width = round($width/6);
$height = round($height/6);
$im = ImageCreateFromjpeg($file);
$overlay = ImageCreateFromjpeg("/home/www/web671/html/cms/logo.jpg");
$im_neu=ImageCreatetruecolor($width,$height);
$black = ImageColorAllocate($im, 000,000,000);
$white = ImageColorAllocate($im, 255,255,255);
// $size = imageTTFbbox($s+2,0,"/home/www/web671/html/website/arialnb.ttf", $text);
$dx = abs($size[2]-$size[0]);
$dy = abs($size[5]-$size[3]);
$xpad=350;
$ypad=230;
ImageCopyResized($im_neu,$im,0,0,0,0, $width,$height,ImageSX($im),ImageSY($im));
ImageCopymerge($im_neu,$overlay,00,00,0,0, 44,260,40);
// ImageTTFText($im_neu, 15, 0, (int)($xpad/2)-160, $dy+(int)($ypad/2)-110, 1*$black, "/home/www/web671/html/website/arialnb.ttf", $text);
Imagejpeg($im_neu, "mediumthumb$file");
printf("<font><span class='bold'>mediumthumb$file</span> in der größe $width x $height wurde erzeugt<br></font><br>");
ImageDestroy($im);
ImageDestroy($im_neu);
}
else
{
//** No Else Comment
}
}
rewinddir($hdl);
closedir($hdl);
?>