我在php中处理图像处理,目前我正在尝试使用php旋转图像(比如在给定角度旋转图像)。 jpg和jpeg图片上的所有内容都很顺利,但是在png图像中失败了。
它会抛出错误:division by zero
。
如果任何人都有很好的想法在GD库中旋转png图像;建议我仅用于GD库。我不能在想象中工作。
$file_ext = preg_split("/\./",$image_name);
$filetype = end($file_ext);
switch($filetype){
case "gif":
$source = imagecreatefromgif($file);
list($width, $height, $type, $attr) = getimagesize($file);
break;
case "jpg":
$source = imagecreatefromjpeg($file);
list($width, $height, $type, $attr) = getimagesize($file);
break;
case "jpeg":
$source = imagecreatefromjpeg($file);
list($width, $height, $type, $attr) = getimagesize($file);
break;
case "png":
// echo 'asdasd';
$source = imagecreatefrompng($file);
//imagealphablending($source, FALSE);
//imagesavealpha($source, TRUE);
list($width, $height, $type, $attr) = getimagesize($file);
break;
}
//echo $width; die;
$tempImg = imagecreatetruecolor($width, $height) or die("Cant create temp image");
imagecopyresized($tempImg, $source, 0, 0, 0, 0, $width, $height, $width, $height) or die("Cant resize copy");
$rotate = imagerotate($source,$angle,imageColorAllocateAlpha($source, 255, 255, 255, 127));
switch($filetype){
case "gif":
@imagegif( $rotate,USER_CROP_FOLDER.$image_name,90);
break;
case "jpg":
@imagejpeg( $rotate,USER_CROP_FOLDER.$image_name,90);
break;
case "jpeg":
@imagejpeg( $rotate,USER_CROP_FOLDER.$image_name,90);
break;
case "png":
imagealphablending($rotate, FALSE);
imagesavealpha($rotate, TRUE);
@imagepng( $rotate,USER_CROP_FOLDER.$image_name,90);
break;
}