2013-04-14

HOWTO: radical lossless JPEG image optimization (in Linux)

(The sample commands are tested under Debian Wheezy).

First of all, don't forget to install the JPEG manipulating programs package:
# apt-get install libjpeg-progs
And it's the optimization itself:
$ jpegtran -copy none -progressive input.jpg > output.jpg
Notes:
  1. yes, it produces a progressive JPEG output image; if you don't like it (or it's unsupported in the target environment), use -optimize switch instead of -progressive (but the output image size will be bigger);
  2. there's also a non-recommended option (an -arithmetic switch) to enable arithmetic coding; it allows a more efficient compression than traditional Huffman coding does, but (unfortunately) it's not widely supported in JPEG decoders due to some historical patent restrictions;
  3. -copy none option removes all extra markers (comments, tags, thumbnails and other metadata) from the output; if you need to save them, use -copy comments (or even -copy all) option instead;
  4. you can add a -grayscale option, and it will omit color data from the output image without re-encoding (very useful for grayscale / black & white / monochrome images);
  5. more reading:

No comments:

Post a Comment