Hi, I have written some code (with a lot of help from people on this forum) and it works perfectly; however the tmp file on my server is being filled up with temporary photos.
I have tried imagedestroy on all photos (and even on things I thought were photos and are not) but the tmp file just keeps mounting up.
Could some one have a quick look and tell me if there is a imagedestroy missing?
I would really appreciate it. Thanks
$tam = getimagesize($foto);
// $da=fopen($foto, "rb");
//if ($tam && $da)
//{
@header("Content-type: {$tam['mime']}");
// fpassthru($da);
// exit;
//}
$mime = $tam['mime'];
$path = $_SERVER['DOCUMENT_ROOT'] . '/fotos_coches/';
if(!empty($foto))
{
// if ($foto_type == "image/gif") { $ext = ".gif"; }
if ($foto_type == "image/pjpeg") { $ext = ".jpg";}
if ($foto_type == "image/jpeg") { $ext = ".jpg";}
$newfotoname = uniqid("").$ext ;
}
// array[0]=width (Of Thumbnail)
// array[1]=height (Of Thumbnail)
//----------------------------
$imagemax[0]=300;
$imagemax[1]=225;
list ($width, $height) = getimagesize($foto);
rename($foto, $foto.$ext);
$im4 = imagecreatefromjpeg($foto.$ext);
$imagedim[0]= $width;
$imagedim[1]= $height;
//----------------------------
// ASPECT RATIO
if (ceil($imagedim[0]/4) > ceil($imagedim[1]/3))
{
$x=0;
$y=1;
}
else
{
$x=1;
$y=0;
}
//--------------------------
$imageprop=($imagemax[$x]*100)/$imagedim[$x];
$imagesize[$y]=($imagedim[$y]*$imageprop)/100 ;
$imagedim[$x]=$imagemax[$x];
$imagedim[$y]=ceil($imagesize[$y]);
$newimagedim[$x]=$imagedim[$x];
$newimagedim[$y]=$imagedim[$y];
$dst_img=@imagecreatetruecolor($newimagedim[0],$newimagedim[1]);
$src_img=@imagecreatefromjpeg($foto.$ext);
ImageCopyResampled($dst_img,$src_img,0,0,0,0,$newimagedim[0],$newimagedim[1],$width,$height);
$filler_img=@imagecreatetruecolor($imagemax[0],$imagemax[1]);
$background_color = imagecolorallocate($filler_img, 255, 255, 255);
imagefill($filler_img, 0,0, $background_color);
$adj_w=($imagemax[0]/2)-ceil($newimagedim[0]/2);
$adj_h=($imagemax[1]/2)-ceil($newimagedim[1]/2);
@imagecopy($filler_img, $dst_img, $adj_w, $adj_h, 0, 0, $newimagedim[0], $newimagedim[1]);
$im4 = imagejpeg($filler_img, $path.$newfotoname, 75);
imagedestroy($src_img);
// imagedestroy($dst_img);
@copy($im4, $path.$newfotoname);
//----------------------------------------------------------------------
// Here we create the thumbnail
$pathmain = $_SERVER['DOCUMENT_ROOT'] . '/fotos_coches/main/';
$dst = ImageCreatetruecolor(200, 150);
ImageCopyResampled($dst, $filler_img, 0,0,0,0, 200, 150, 300, 225);
error_reporting(0);
header("Content-type: image/jpeg");
ImageJPEG($dst, $pathmain.$newfotoname, 75);
ImageDestroy($filler_img);
ImageDestroy($dst);
ImageDestroy($dst_img);
I tried imagedestroy($im4) and also for the original $foto and for $foto.$ext.