JPG文件大小优化 - PHP,ImageMagick,&谷歌的页面速度 [英] JPG File Size Optimization - PHP, ImageMagick, & Google's Page Speed
问题描述
我有照片库代码,可以进行图像重新调整大小和创建缩略图。我使用ImageMagick来做到这一点。我通过谷歌的页面速度工具运行了一个画廊页面,它显示重新调整大小的图像和缩略图都有大约10KB的数据(特别是JPEG文件)。
I have photo gallery code that does image re-sizing and thumbnail creation. I use ImageMagick to do this. I ran a gallery page through Google's Page Speed tool and it revealed that the re-sized images and thumbnails both have about an extra 10KB of data (JPEG files specifically).
我可以添加哪些内容来优化文件大小?
What can I add to my scripts to optimize the file size?
附加信息
我使用 imagick :: FILTER_LANCZOS
过滤器,模糊设置为 0.9
调用 resizeImage()
函数时。 JPEG的质量设置为 80
。
I am using the imagick::FILTER_LANCZOS
filter with a blur setting of 0.9
when calling the resizeImage()
function. JPEGs have a quality setting of 80
.
推荐答案
我发现这个SO问题, JPEG优化工具?,它有一些很好的信息,但解决方案是在PHP之外。使用该问题解决方案的提示我发现可以执行两个无损优化:
I found this SO question, "Tools for JPEG optimization?", that has some good information, but the solutions are outside of PHP. Using hints from that question's solutions I found that there were two lossless optimizations that could be performed:
- 霍夫曼编码表的优化
- 删除元数据(EXIF等)
两者都可以用<$ c来完成$ c> ImageMagick 这样:
- 根据 ImageMagick文档,默认情况下计算最佳霍夫曼编码表。这个步骤已经完成了,耶!
- 删除元数据可以通过使用 stripImage( )方法。
- According to ImageMagick documentation, the optimal Huffman coding tables are computed by default. This step is already taken care of, yay!
- Removal of meta-data can be accomplished very simply by using the stripImage() method.
我测试的一张图片减少了12KB。 600x450文件从63.42KB变为51.42KB,140x105缩略图从17.98KB变为5.98KB。
One image I tested was reduced by 12KB. The 600x450 file went from 63.42KB to 51.42KB, and the 140x105 thumbnail went from 17.98KB to 5.98KB.
这篇关于JPG文件大小优化 - PHP,ImageMagick,&谷歌的页面速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!