Tools for JPEG optimization?

OptimizationJpeg

Optimization Problem Overview


Do you know of any tools (preferrably command-line) to automatically and losslessly optimize JPEGs that I could integrate into our build environment? For PNGs I'm currently using PNGOUT, and it generally saves around 40% bandwidth/image size.

At the very least, I would like a tool that can strip metadata from the JPGs - I noticed a strange case where I tried to make thumbnail from a photograph, and couldn't get it smaller than 34 kB. After investigating more, I found that the EXIF data was still part of the image, and the thumbnail was 3 kB after removing the metadata.

And beyond that - is it possible to further optimize JPGs losslessly? The PNG optimizer tries different compression strategies, random initialization of the Huffmann encoding etc.

I am aware that most savings come from the JPEG quality parameter, and that it's a rather subjective measure. I'm only looking for a tool that can be run as a build step and that losslessly squeezes a few bytes from the images.

Optimization Solutions


Solution 1 - Optimization

I wrote a GUI for all image optimization tools I could find, including MozJPEG and jpegoptim that optimize Huffman tables, progressive scans, and (optionally) remove invisible metadata.

ImageOptim smushing it

If you don't have a Mac, I also have a basic web interface that works on any platform.

Solution 2 - Optimization

I use libjpeg for lossless operations. It contains a command-line tool jpegtran that can do all you want. With the commandline option -copy none all the metadata is stripped, and -optimize does a lossless optimization of the Huffmann compression. You can also convert the images to progressive mode with -progressive, but that might cause compatibility problems (does anyone know more about that?)

Solution 3 - Optimization

A new service called JPEGmini produces incredible results. A shame that it's online only. Edit: It's available for Windows and Mac now

Solution 4 - Optimization

[WINDOWS ONLY]

RIOT(Radical Image Optimization Tool) This is the greatest image optimization tool I have found!

http://luci.criosweb.ro/riot/

You can easily get a 10MB image down to 800KB through sub-sampling. It supports PNG, GIF, and JPEG. It even integrates into context menus so you can send pictures straight there. Allows you to rotate, re-size, compress to specified KB's, and more. Also has plugins for GIMP and IrfanView and other things.

There is also a DLL available if you want to incorporate it into your own programs or java script / c++ program.

Another alternative is http://pnggauntlet.com/ PNGGAUNTLET takes forever but it does a pretty good job.

[WINDOWS ONLY]

Solution 5 - Optimization

Tried a number of the suggestions above - I personally was after lossless compression.

My sample image had an original size of 67,737 bytes.

Using kraken.io, it went down to 64,718 Using jpegtran, it went down to 64,718 Using yahoo smush-it, it went down to 61,746 Using imagemagick (-strip), it went down to 65,312

The smush.py option looks promising, but the installation was too complex for me to do quickly

jpegrescan looks promising too, but seems to be unix and I'm using windows

jpegmini is NOT lossless, but I can't tell the difference (down to 22,172)

plinth's Altrasoft jpegstripper app does not work on my windows 7

jpegoptim is not windows - no good for me

Riot (keeping quality at 100%) got it down to 63,416 and with chroma subsampling set to high, it got it down to 61,912 - I don't know if that is lossless or not though, and I think it looks lighter than the original.

So my verdict is yahoo smushit if it must be lossless

Solution 6 - Optimization

I would try Imagemagick. It has tons of command line options, its free and have a nice license. <http://www.imagemagick.org>

There seems to be an option called Strip that may help you: <http://www.imagemagick.org/script/command-line-options.php#strip>

Solution 7 - Optimization

ImageOptim is really slick. The command line option posted by the author will populate the GUI and show progress. I used jpegtran for optimizing and converting to progressive, then ImageOptim for further progressive optimizations and for other file types.

Reuse of script code also found in this forum (all files replaced in place):

jpegtran

for file in $(find $DIR -type f \( -name "*.jpg" -or -name "*.jpeg" -or -name "*.JPG" \)); do
    echo found $file for optimizing...
    jpegtran -copy comments -optimize -progressive -outfile $file $file
done

ImageOptim

for file in $(find $DIR -type f \( -name "*.jpg" -or -name "*.png" -or -name "*.gif" \)); do
do
    echo found $file for optimizing...
    open -a ImageOptim.app $file
done

Solution 8 - Optimization

In case anyone's looking, I've written an offline version of Yahoo's Smush.it. It will losslessly optimise pngs, jpgs and gifs (animated and static):

http://github.com/thebeansgroup/smush.py

Solution 9 - Optimization

You can use jpegoptim which will losslessly optimize jpeg files by default. The --strip-all option strips all extra embedded info. You can also specify a lossy mode with the --max switch which is useful when you have images saved with a very high quality setting, which is not necessary for eg. web content.

You get similar optimization as with jpegtran (see answer by OutOfMemory) but jpegoptim can't save to progressive jpegs.

Solution 10 - Optimization

I've written a command line tool called 'picopt' (similar to ImageOptim) that uses external programs to optimize JPEGs, PNGs, GIFS, animated GIFS and even comic book archive contents (CBR/CBZ).

This is suitable for use with homebrew on OS X or Linux systems where you have installed tools like jpegrescan, jpegtran, optipng, gifsicle, etc.

https://github.com/ajslater/picopt

Solution 11 - Optimization

I too would recommend ImageMagick. It has a command line option to remove EXIF metadata

mogrify -strip image.jpg

There are plenty of other tools out there that do the same thing.

As far as recompressing JPEGs go, don't. JPEGs are lossy to start with, so any form of recompression is only going to hurt image quality. However, if you have losslessly encoded images, some encoders do a better job than others. I have noticed that JPEGs done with Photoshop consistently look better than when encoded with ImageMagick (despite the same file size) due to complicated reasons. Furthermore (and this is relevant to you), I know that at least Photoshop can save JPEGs as optimized which means they drop compatibility with some stuff that you probably don't care about to save a couple of KB. Also, make sure you don't have any colour profiles embedded and you may be able to save another couple of KB.

Solution 12 - Optimization

I would recommend using http://kraken.io It's ultra-fast webapp which will optimize your PNG and JPEG files far better than smush.it does.

Solution 13 - Optimization

I recommend to use JpegOptim, it's free and really nice, you can specify the quality, the size you want ... And easy to use in command line.

JpegOptim

Solution 14 - Optimization

May I recommend this for near-transparency:

convert 'yourfile.png' ppm:- | jpeg-recompress -t 97 -q veryhigh -a -m smallfry -s -r -S disable - yourfile.jpg

It uses imagemagick's convert and jpeg-recompress from jpeg-archive.

Both are open-source and work on Windows, Mac and Linux. You may want to tweak the options above for different quality expectations.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionchris166View Question on Stackoverflow
Solution 1 - OptimizationKornelView Answer on Stackoverflow
Solution 2 - OptimizationOutOfMemoryView Answer on Stackoverflow
Solution 3 - OptimizationEduardo MolteniView Answer on Stackoverflow
Solution 4 - OptimizationBenView Answer on Stackoverflow
Solution 5 - OptimizationGraham ButcherView Answer on Stackoverflow
Solution 6 - OptimizationborjabView Answer on Stackoverflow
Solution 7 - Optimizationbsy-webView Answer on Stackoverflow
Solution 8 - OptimizationtimmyView Answer on Stackoverflow
Solution 9 - OptimizationbluegrayView Answer on Stackoverflow
Solution 10 - OptimizationAJ SlaterView Answer on Stackoverflow
Solution 11 - OptimizationDavid JohnstoneView Answer on Stackoverflow
Solution 12 - OptimizationPonoView Answer on Stackoverflow
Solution 13 - Optimizationagonist_View Answer on Stackoverflow
Solution 14 - OptimizationCamilo MartinView Answer on Stackoverflow