是否可以在 PHP 中对 JPEG 图像执行无损旋转?
我需要旋转一些现有的 JPG 图像。它们已经丢失了一些细节,但我现在想旋转它们并且不再丢失更多细节。
经过一番研究,似乎 PHP 唯一的无损图像旋转库是使用 jPegTran 库。
当需要进行无损 jpg 旋转时,还有其他选择吗?
谢谢!
I need to rotate some existing JPG images. They have already lost some detail, but I now want to rotate them and lose no further detail.
With a little research, it seems the only lossless Image rotation library for PHP is by using the jPegTran library.
Are there any other options when it somes to doing lossless jpg rotation?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是否可以通过 exec('commandline'); 调用外部程序 losslessrotator ?
另一种选择是 jpegclub 的 jpegtran
Would't it be possible to call an external program say losslessrotator by exec('commandline');
Another option would be jpegtran by jpegclub
当顺时针或逆时针旋转 90 度时,请注意 jpegtran,它不会按预期旋转所有像素,因为它只能在尺寸为 jpeg 块大小(通常为 8x8 像素)倍数的区域内进行无损旋转。它在内部旋转每个块内的像素以避免图像的重新压缩,但边缘块不能像那样旋转。因此,使用 jpegtran -rotate 90 或 270 时,边缘上会留下一小条未旋转的像素,您需要使用 -trim 选项来删除它们,但生成的图像会小几个像素比原来的。
因此,虽然这是无损旋转,但您最终仍然会在此过程中丢失一些像素。
Be careful about jpegtran when rotating cw or ccw by 90 degrees, it will not rotate all of the pixels as expected, as it can do losslless rotation only within area which dimensions are the multiple of jpeg block size (8x8 pixels usually). It rotates pixels inside each of these blocks internally to avoid re-compression of the image, but the edge blocks can't be rotated like that. So with jpegtran -rotate 90 or 270 you will be left with a tiny strip of un-rotated pixels on the edge, and you need to use -trim option to get rid of them, but then the resulting image will be a few pixels smaller than the original.
So while it is a lossless rotation, you still end up loosing some pixels in the process.
JPEG 是一种有损格式,因此答案是否定的,您无法在任何应用程序、编程语言或大师冥想上创建 JPEG 的无损旋转。
但是,如果您以 JPEG 格式保存,则可以在保存旋转的 JPEG 时使用
$quality
参数来最大程度地减少图像数据丢失。如果您以无损格式保存它,那么您已经最大限度地减少了图像数据丢失。例子:
JPEG is a lossy format, so the answer is no, you can't create a lossless rotate of JPEG on any application, programming language, or guru meditation.
What you can do, however, is minimize image data loss by using the
$quality
argument when saving the rotated JPEG, if you're saving it in JPEG format that is. If you're saving it in lossless format, then you've already minimized image data loss.Example: