我一直在研究一个系统来旋转上传的图像。该算法的工作原理如下:
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)