Home >Backend Development >PHP Tutorial >php怎么实现png图片旋转

php怎么实现png图片旋转

PHPz
PHPzOriginal
2016-06-06 20:41:371303browse

php怎么实现png图片旋转

php实现png图片旋转的方法:

function pic_rotating($degrees,$url){
$srcImg = imagecreatefrompng($url);//获取图片资源
$rotate = imagerotate($srcImg, $degrees, 0);//原图旋转
 
//获取旋转后的宽高
$srcWidth = imagesx($rotate);
$srcHeight = imagesy($rotate);
 
//创建新图
$newImg = imagecreatetruecolor($srcWidth, $srcHeight);
 
//分配颜色 + alpha,将颜色填充到新图上
$alpha = imagecolorallocatealpha($newImg, 0, 0, 0, 127);
imagefill($newImg, 0, 0, $alpha);
 
//将源图拷贝到新图上,并设置在保存 PNG 图像时保存完整的 alpha 通道信息
imagecopyresampled($newImg, $rotate, 0, 0, 0, 0, $srcWidth, $srcHeight, $srcWidth, $srcHeight);
imagesavealpha($newImg, true);
//生成新图
imagepng($newImg, $url);
}
 
$degrees = 90;//旋转角度
$url = './111111111111/154020404057861.png';//图片存放位置
pic_rotating($degrees,$url);

更多相关技术文章,请访问PHP中文网

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn