//用给定角度旋转图像,以jpeg图像格式为例
function rotate($filename,$degrees){
$img = getimagesize($filename);
$mime = $img["mime"];//$img->getImageInfo();
$source = null;
switch ($mime)
{
case 'image/png':$source = imagecreatefrompng($filename);
break;
case 'image/gif':$source = imagecreatefromgif($filename);
break;
case 'image/jpg':$source = imagecreatefromjpeg($filename);
break;
case 'image/jpeg':$source = imagecreatefromjpeg($filename);
break;
}
//使用imagerotate()函数按指定的角度旋转
$rotate = imagerotate($source, $degrees, 0);
//旋转后的图片保存
switch ($mime)
{
case 'image/png':imagepng($rotate,$filename,100);
break;
case 'image/gif':imagegif($rotate,$filename,100);
break;
case 'image/jpg':imagejpeg($rotate,$filename,100);
break;
case 'image/jpeg':imagejpeg($rotate,$filename,100);
break;
}
}
调用例子:
$filename = "./login.png";
rotate($filename,90);
图像旋转逆时针
最新推荐文章于 2021-02-12 16:13:05 发布