From dd7bbbf4ad5dd98d77769170867a5ab4e198b565 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sat, 3 Dec 2005 14:37:13 +0100 Subject: cleanups in resize_imageGD (maybe #631) darcs-hash:20051203133713-7ad00-6c4d3126fb5de8e5396c214b1f6c82f99eca98ae.gz --- lib/exe/fetch.php | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'lib/exe/fetch.php') diff --git a/lib/exe/fetch.php b/lib/exe/fetch.php index 89c88090c..efca50f18 100644 --- a/lib/exe/fetch.php +++ b/lib/exe/fetch.php @@ -224,7 +224,10 @@ function resize_imageGD($ext,$from,$from_w,$from_h,$to,$to_w,$to_h){ $newimg = @imagecreatetruecolor ($to_w, $to_h); } if(!$newimg) $newimg = @imagecreate($to_w, $to_h); - if(!$newimg) return false; + if(!$newimg){ + imagedestroy($image); + return false; + } //keep png alpha channel if possible if($ext == 'png' && $conf['gdlib']>1 && function_exists('imagesavealpha')){ @@ -232,9 +235,6 @@ function resize_imageGD($ext,$from,$from_w,$from_h,$to,$to_w,$to_h){ imagesavealpha($newimg,true); } - // create cachedir - //io_makeFileDir($to); // not needed anymore, should exist - //try resampling first if(function_exists("imagecopyresampled")){ if(!@imagecopyresampled($newimg, $image, 0, 0, 0, 0, $to_w, $to_h, $from_w, $from_h)) { @@ -244,18 +244,32 @@ function resize_imageGD($ext,$from,$from_w,$from_h,$to,$to_w,$to_h){ imagecopyresized($newimg, $image, 0, 0, 0, 0, $to_w, $to_h, $from_w, $from_h); } + $okay = false; if ($ext == 'jpg' || $ext == 'jpeg'){ - if(!function_exists("imagejpeg")) return false; - return imagejpeg($newimg, $to, 70); + if(!function_exists('imagejpeg')){ + $okay = false; + }else{ + $okay = imagejpeg($newimg, $to, 70); + } }elseif($ext == 'png') { - if(!function_exists("imagepng")) return false; - return imagepng($newimg, $to); + if(!function_exists('imagepng')){ + $okay = false; + }else{ + $okay = imagepng($newimg, $to); + } }elseif($ext == 'gif') { - if(!function_exists("imagegif")) return false; - return imagegif($newimg, $to); + if(!function_exists('imagegif')){ + $okay = false; + }else{ + $okay = imagegif($newimg, $to); + } } - return false; + // destroy GD image ressources + if($image) imagedestroy($image); + if($newimg) imagedestroy($newimg); + + return $okay; } -- cgit v1.2.3