I know how to optimize and compress png images using optipng command. line tool. I have lots of images in JPEG format. How do I compress and optimize JPEG images on my amazon cloud account so that I can save bandwidth on cloudfront cdn account? How do I use an image compressor to create lossless compression on JPEG files, with no effect on image quality in bulk using Linux?
JPG file format is recommended for high resolution photographic-style images. You need to use jpegoptim command. It is used to optimize/compress jpeg files. Program supports lossless optimization, which is based on optimizing the Huffman tables. And so called “lossy” optimization where in addition to optimizing Huffman tables user can specify upperlimit for image quality.
Type the following command:
$ apt-get install jpegoptim
[sudo] password for vivek:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libavutil-extra-51 libggiwmh0-target-x libggi2 libgii1 libvo-aacenc0
libgii1-target-x mplayer-skin-blue libggiwmh0 libggi-target-x
Use 'apt-get autoremove' to remove them.
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 5 not upgraded.
Need to get 14.0 kB of archives.
After this operation, 77.8 kB of additional disk space will be used.
Get:1 http://mirror.anl.gov/debian/ squeeze/main jpegoptim amd64 1.2.3-2+b1 [14.0 kB]
Fetched 14.0 kB in 1s (11.2 kB/s)
Selecting previously deselected package jpegoptim.
(Reading database ... 333683 files and directories currently installed.)
Unpacking jpegoptim (from .../jpegoptim_1.2.3-2+b1_amd64.deb) ...
Processing triggers for man-db ...
Setting up jpegoptim (1.2.3-2+b1) ...
The syntax is:
jpegoptim [options] file.jpeg
Type the following command to optimize photo.jpeg, enter:
$ jpegoptim photo.jpeg
photo.jpeg 1312x948 24bit JFIF [OK] 25226 --> 10744 bytes (57.41%), optimized.
How do I process files in batch?
Use the bash for loop as follows:
for i in one.jpeg two.jpeg foo.jpeg; do jpegoptim "$i"; done
## process all *.jpeg in the current directory
for i in *.jpeg; do jpegoptim "$i"; done
From the man page:
Sets alternative destination directory where to save optimized files (default is to overwrite the originals). Please note that unchanged
files won't be added to the destination directory. This means if the source file can't be compressed, no file will be created in the destinaâ€
Force optimization, even if the result would be larger than the original file.
Displays short usage information and exits.
Sets the maximum image quality factor (disables lossless optimization mode, which is by default enabled). This option will reduce quality of
those source files that were saved using higher quality setting. While files that already have lower quality setting will be compressed
using the lossless optimization method.
Don't really optimize files, just print results.
Overwrite target file even if it exists (when using -d option).
Preserve file modification times.
Print totals after processing all files.
Enables verbose mode (positively chatty).
Strip all (Comment & Exif) markers from output file. (NOTE! by default only Comment & Exif markers are kept, everything else is discarded)
Strip Comment (COM) markers from output file.
Strip EXIF markers from output file.
Strip IPTC markers from output file.
Strip ICC profiles from output file.
- jpegoptim home page.
- See man page – jpegoptim(1)