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

php怎么实现png图片旋转

PHPz
Release: 2020-09-04 17:27:45
Original
1318 people have browsed it

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);
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template