#18883411 : check the existence of imagecreate function before calling it

git-svn-id: http://xe-core.googlecode.com/svn/sandbox@7433 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
haneul 2010-05-11 08:21:38 +00:00
parent c67daa3cf0
commit 76c69c6405

View file

@ -499,34 +499,36 @@
$target_type = strtolower($target_type); $target_type = strtolower($target_type);
// create temporary image with target size // create temporary image with target size
if(function_exists('imagecreatetruecolor')) $thumb = @imagecreatetruecolor($resize_width, $resize_height); if(function_exists('imagecreatetruecolor')) $thumb = imagecreatetruecolor($resize_width, $resize_height);
else $thumb = @imagecreate($resize_width, $resize_height); else if(function_exists('imagecreate')) $thumb = imagecreate($resize_width, $resize_height);
else return false;
if(!$thumb) return false;
$white = @imagecolorallocate($thumb, 255,255,255); $white = imagecolorallocate($thumb, 255,255,255);
@imagefilledrectangle($thumb,0,0,$resize_width-1,$resize_height-1,$white); imagefilledrectangle($thumb,0,0,$resize_width-1,$resize_height-1,$white);
// create temporary image having original type // create temporary image having original type
switch($type) { switch($type) {
case 'gif' : case 'gif' :
if(!function_exists('imagecreatefromgif')) return false; if(!function_exists('imagecreatefromgif')) return false;
$source = @imagecreatefromgif($source_file); $source = imagecreatefromgif($source_file);
break; break;
// jpg // jpg
case 'jpeg' : case 'jpeg' :
case 'jpg' : case 'jpg' :
if(!function_exists('imagecreatefromjpeg')) return false; if(!function_exists('imagecreatefromjpeg')) return false;
$source = @imagecreatefromjpeg($source_file); $source = imagecreatefromjpeg($source_file);
break; break;
// png // png
case 'png' : case 'png' :
if(!function_exists('imagecreatefrompng')) return false; if(!function_exists('imagecreatefrompng')) return false;
$source = @imagecreatefrompng($source_file); $source = imagecreatefrompng($source_file);
break; break;
// bmp // bmp
case 'wbmp' : case 'wbmp' :
case 'bmp' : case 'bmp' :
if(!function_exists('imagecreatefromwbmp')) return false; if(!function_exists('imagecreatefromwbmp')) return false;
$source = @imagecreatefromwbmp($source_file); $source = imagecreatefromwbmp($source_file);
break; break;
default : default :
return; return;
@ -545,8 +547,8 @@
} }
if($source) { if($source) {
if(function_exists('imagecopyresampled')) @imagecopyresampled($thumb, $source, $x, $y, 0, 0, $new_width, $new_height, $width, $height); if(function_exists('imagecopyresampled')) imagecopyresampled($thumb, $source, $x, $y, 0, 0, $new_width, $new_height, $width, $height);
else @imagecopyresized($thumb, $source, $x, $y, 0, 0, $new_width, $new_height, $width, $height); else imagecopyresized($thumb, $source, $x, $y, 0, 0, $new_width, $new_height, $width, $height);
} else return false; } else return false;
// create directory // create directory
@ -557,26 +559,26 @@
switch($target_type) { switch($target_type) {
case 'gif' : case 'gif' :
if(!function_exists('imagegif')) return false; if(!function_exists('imagegif')) return false;
$output = @imagegif($thumb, $target_file); $output = imagegif($thumb, $target_file);
break; break;
case 'jpeg' : case 'jpeg' :
case 'jpg' : case 'jpg' :
if(!function_exists('imagejpeg')) return false; if(!function_exists('imagejpeg')) return false;
$output = @imagejpeg($thumb, $target_file, 100); $output = imagejpeg($thumb, $target_file, 100);
break; break;
case 'png' : case 'png' :
if(!function_exists('imagepng')) return false; if(!function_exists('imagepng')) return false;
$output = @imagepng($thumb, $target_file, 9); $output = imagepng($thumb, $target_file, 9);
break; break;
case 'wbmp' : case 'wbmp' :
case 'bmp' : case 'bmp' :
if(!function_exists('imagewbmp')) return false; if(!function_exists('imagewbmp')) return false;
$output = @imagewbmp($thumb, $target_file, 100); $output = imagewbmp($thumb, $target_file, 100);
break; break;
} }
@imagedestroy($thumb); imagedestroy($thumb);
@imagedestroy($source); imagedestroy($source);
if(!$output) return false; if(!$output) return false;
@chmod($target_file, 0644); @chmod($target_file, 0644);