我正在从另一个现有图像中裁剪图像。它适用于 jpg、jpeg、gif 正常工作。但它不适用于 png 图像文件。给出以下错误。
Warning (2): imagecreatefrompng() [function.imagecreatefrompng]: '/var/www/shareme/app/webroot//documents/users/MTI5NzkyMjQzMmZmLWxvZ28tYmlnLnBuZw.png' is not a valid PNG file [APP/controllers/components/jq_imgcrop.php, line 80]
这是代码。
function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale){
$newImageWidth = ceil($width * $scale);
$newImageHeight = ceil($height * $scale);
$ext = strtolower(substr(basename($image), strrpos(basename($image), ".") + 1));
$source = "";
if($ext == "png"){
$source = imagecreatefrompng($image);
}elseif($ext == "jpg" || $ext == "jpeg"){
$source = imagecreatefromjpeg($image);
}elseif($ext == "gif"){
$source = imagecreatefromgif($image);
}
$newImage = imagecreatetruecolor($newImageWidth,$newImageHeight);
imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height);
imagejpeg($newImage,$thumb_image_name,90);
chmod($thumb_image_name, 0777);
return $thumb_image_name;
}
你对这个问题有任何想法吗?