Apache Eating up ram using imagecreatefrom
am 05.04.2008 05:18:32 von Extremest (ExtremestI have a picture site. I save the original and a thumbnail of every
picture. Now if they click on a thumbnail then they go to the
viewer page where they then see an intermediate picture. I have php
opening the original and resizing it and sending the resized image
out. It works great and not much load. Better than having 1.7
million more pics. Problem I am having is that after a few hours
apache is like 700 megs in memory and will start messing up. Is
there a memory leak in this function or something where it cannot
unload the memory used from the pics? Here is my resize image code
that I have so far.
if(isset($_GET['image']))
{
$filename = $_GET['image'];
$dir = "pics/".substr($filename,0,2);
$srcsize = getimagesize($dir."/".$filename);
switch($srcsize['mime'])
{
case "image/jpeg":
$src_img = imagecreatefromjpeg($dir."/".
$filename);
break;
case "image/png":
$src_img = imagecreatefrompng($dir."/".
$filename);
break;
case "image/gif":
$src_img = imagecreatefromgif($dir."/".
$filename);
break;
}
if($srcsize[0] > $srcsize[1])
{
$dest_w = 420;
$dest_h = (420 / $srcsize[0]) * $srcsize[1];
}else{
$dest_w = (420 / $srcsize[1]) * $srcsize[0];
$dest_h = 420;
}
//echo $dest_w."--".$dest_h."--".$srcsize[1]."--".$srcsize
[0];
$dst_img = imagecreatetruecolor($dest_w, $dest_h);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_w,
$dest_h, $srcsize[0], $srcsize[1]);
switch($srcsize['mime'])
{
case "image/jpeg":
header("content-type: image/jpeg");
imagejpeg($dst_img);
break;
case "image/png":
header("content-type: image/png");
imagepng($dst_img);
break;
case "image/gif":
header("content-type: image/gif");
imagegif($dst_img);
break;
}
// Destroy images
imagedestroy($src_img);
imagedestroy($dst_img);
}