I am cropping image from another existing image. It works for jpg, jpeg, gif works properly. But it is not working for png image files. Giving following error.
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]
Here is the code for that.
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;
}
have you any idea about the problem?
Maybe you also want to check for the mime type instead of a potentially faulty extension.