我一直在研究一个系统来旋转上传的图像。该算法的工作原理如下:
1) User uploads a jpeg. It gets saved as a PNG
2) Link to the temp png is returned to the user.
3) The user can click 90left,90right, or type in N degrees to rotate
4) The png is opened using
$image = imagecreatefrompng("./fileHERE");
5) The png is rotated using
$imageRotated = imagerotate($image,$degrees,0);
6) The png is saved and the link returned to the user.
7) If the user wishes to rotate more go back to step 3 operating on the newly
saved temporary PNG,
else the changes are commited and the final image is saved as a jpeg.当向左和向右旋转90度时,这个效果非常好。用户可以多次无限旋转而不会有任何质量损失。问题是,当用户尝试旋转20度(或其他非90度的倍数)时。当旋转20度时,图像会稍微旋转,并形成一个黑框来填充需要填充的区域。由于图像(带有黑盒)被保存为png,因此下一次旋转20度会将图像(带有黑盒)再旋转20度,并形成另一个黑盒来填补空白。长话短说,如果你这样做到360度,你会有一个很大的黑盒围绕着一个非常小的剩余图像。即使你放大并裁剪出黑盒,质量也会有明显的下降。
我有办法避开黑匣子吗?(服务器未安装imagick )
发布于 2012-10-15 21:56:45
始终存储未修改的源文件,并在旋转时使用原始源文件旋转度数。所以20度+ 20度,意味着将源旋转40度。
$image = imagecreatefromjpeg("./source.jpg");
//如果是第一次没有旋转数据,如果(!isset( $_SESSION"degrees“)) $_SESSION"degrees”=0,则设置;//应用新的旋转$_SESSION“degrees”+= $degrees;//旋转图片$rotated =+=$degrees($image,$_SESSION"degrees",0);//保存图片,不要修改源文件!imagejpeg($rotated,"./ last.jpg ");//输出图片头部(“Content-Type: image/jpeg");imagejpeg($rotated);
$_SESSION["degrees"]参数。https://stackoverflow.com/questions/12897104
复制相似问题