JPG File Size Optimization - PHP, ImageMagick, & Google's Page Speed

五迷三道 提交于 2019-11-29 02:10:27
Sonny

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:

  1. Optimization of the Huffman coding tables
  2. Removal of meta-data (EXIF, etc)

Both of can be accomplished with ImageMagick this way:

  1. According to ImageMagick documentation, the optimal Huffman coding tables are computed by default. This step is already taken care of, yay!
  2. Removal of meta-data can be accomplished very simply by using the stripImage() method.

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.

Run your images through Yahoo's SmushIt service, where the images are converted to a PNG with an exact number of colors. No loss in quality, but a loss in weight :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!