Dead function
Date: 02/06/06
(PHP Community) Keywords: php, mysql, sql, web
Ok, I have the following function that until the other day worked fine.
It has now stopped and i have no idea why. The only think i know of
that has been done on my web server recently is MYSQL have been
upgraded.
function img_resize($path,$w,$h,$quality,$save){
$image_data=@getimagesize($path);
$image_type=$image_data[2];
$gd_ext=array('','jpg','gif');
if($image_type!=1&&$image_type!=2) return false;
if($save=='') header('Content-type: '.$image_data['mime']); else $save=eregi_replace('%ext',$gd_ext[$image_type],$save);
if($w!=0){
$rapporto=$image_data[0]/$w;
if($h!=0){
if($image_data[1]/$rapporto>$h) $rapporto=$image_data[1]/$h;
}
}elseif($h!=0){
$tmp_h=$image_data[1]/$h;
}else{
return false;
}
$thumb_w=$image_data[0]/$rapporto;
$thumb_h=$image_data[1]/$rapporto;
if($image_type==1) $img_src=@imagecreatefromgif($path);
elseif($image_type==2) $img_src=@imagecreatefromjpeg($path);
$img_thumb=@imagecreatetruecolor($thumb_w,$thumb_h);
$result=@imagecopyresampled($img_thumb,$img_src,
0,0,0,0,$thumb_w,$thumb_h,$image_data[0],$image_data[1]);
if(!$img_src||!$img_thumb||!$result) return false;
if($image_type==1) $result=@imagegif($img_thumb,$save);
elseif($image_type==2) $result=@imagejpeg($img_thumb,$save,$quality);
return $result;
}
Now
this code is meant to take an image (full path including filename as
$path) and make it the size set when called and then save it to the
name and path set as $save.
When it makes this file, it is a
copy, so nothing is done to the original. Now this function is part of
the admin section to my gallery which is there just to make and store
the thumbnails. I have no idea why this isn’t working, but I have tried
a few of the scripts in the php docs with no luck. Php is working, so
it isn’t that, so does anyone know how I could do this function in the
most compataible way possible? Bear in mind I’m still a bit of a n00b,
well with image manipulation at least.
Thanks for any help.
Source: http://community.livejournal.com/php/408971.html