Search

11/15/2008

Image Optimization, Part 3: Four Steps to File Size Reduction » Yahoo! User Interface Blog

Image Optimization, Part 3: Four Steps to File Size Reduction » Yahoo! User Interface Blog
< pngcrush -rem alla -brute -reduce src.png dest.png
* src.png is the source image, dest.png is the destination (result) image
* -rem alla means remove all chunks but keeps the one for transparency
* -reduce tries to reduce the number of colors in the palette if this is possible
* -brute tries over a hundred different methods for optimization in addition to the default 10. It’s slower and most of the times doesn’t improve much. But if you’re doing this process “offline”, one or two more seconds are not important since there’s a chance if a filesize win. Remove this option in performance-sensitive scenarios.
Here's a command to copy the source image, optimize it and don’t carry over any metadata in the new copy:
< jpegtran -copy none -optimize src.jpg dest.jpg
You may be able to further improve image size by using jpegtran's -progressive option. It produces JPEGs that load progressively in the browser, starting from a lower quality version of the image and improving as new image information arrives. You can see this behavior if you look at photos on Picassa, but you have to switch photos fast, because otherwise while you’re looking at one, the next one is being preloaded.
Important note on stripping meta information: do it only for images that you own, because when jpegtan strips all the meta, it also strips any copyright information contained in the image file.
In order to automatically change your GIFs, you can use ImageMagick’s convert:
< convert image.gif image.png
If you want to force PNG8 format you can use:
< convert image.gif PNG8:image.png
tools:
1. ImageMagick to identify the image type and to convert GIFs to PNG.
2. pngcrush to strip unneeded chunks from PNGs. We're currently experimenting with other PNG tools such as pngout, optipng, pngrewrite that will allow for even better png optimization.
3. jpegtran to strip all meta data from JPEGs (currently disabled) and try progressive JPEGs.
4. gifsicle to optimize GIF animations by striping repeating pixels in different frames.

沒有留言: