Howtos / Articles

Optimizing jpeg Image Files on Linux

Optimizing images can be a quick and easy way to shrink the file size of jpeg images, removing unneeded data within the file. This can reduce the time it takes users to download the images if they are on a web server. It can also be used to remove comment and exif data from the files, so there is no added information within the file, other than the image itself.

“jpegoptim” is a free application that can be used to optimize jpeg image files.

Installing jpegoptim:

$ sudo apt-get install jpegoptim

Using jpegoptim:

Strip all exif and comment markers:

$ jpegoptim --strip-all -t *.jpg

Sample output:

$ jpegoptim --strip-all -t *.jpg
image1.jpg 150x129 24bit JFIF  [OK] 6225 --> 5543 bytes (10.96%), optimized.
image2.jpg 150x23 24bit JFIF  [OK] 1822 --> 1437 bytes (21.13%), optimized.
image3.jpg 300x47 24bit JFIF  [OK] 4970 --> 4533 bytes (8.79%), optimized.
image4.jpg 400x63 24bit JFIF  [OK] 7601 --> 7079 bytes (6.87%), optimized.
image5.jpg 810x129 24bit JFIF  [OK] 36794 --> 32829 bytes (10.78%), optimized.
Average compression (5 files): 11.70% (6k)

Recursively optimize all jpeg files:

$ find . -name '*.jpg' | xargs jpegoptim --strip-all

Full Usage Options:

jpegoptim v1.2.3  Copyright (c) Timo Kokkonen, 1996-2009.
Usage: jpegoptim [options] 

  -d, --dest=
                  specify alternative destination directory for
                  optimized files (default is to overwrite originals)
  -f, --force     force optimization
  -h, --help      display this help and exit
  -m[0..100], --max=[0..100]
                  set maximum image quality factor (disables lossless
                  optimization mode, which is by default on)
  -n, --noaction  don't really optimize files, just print results
  -o, --overwrite overwrite target file even if it exists
  -p, --preserve  preserve file timestamps
  -q, --quiet     quiet mode
  -t, --totals    print totals after processing all files
  -v, --verbose   enable verbose mode (positively chatty)
  -V, --version   print program version

  --strip-all     strip all (Comment & Exif) markers from output file
  --strip-com     strip Comment markers from output file
  --strip-exif    strip Exif markers from output file
  --strip-iptc    strip IPTC markers from output file
  --strip-icc     strip ICC profile markers from output file

Share this howto article!
  • Facebook
  • Twitter
  • Reddit
  • email

Leave a Reply




You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>