I have found this tool that optimizes images for the web. What is surprising for me (of course, there will be other tools like this :)) is that it only optimizes the uploaded image if it is possible, I mean, if it considers that the image is already optimized for the web it says "No savings".

My question: before running something like convert -quality 80, is there any way (using ImageMagick or any other tool in Linux) to ckeck if an image is already optimized for the web? In that case I would not run convert -quality 80.

  • 1
    Looking at the brief delay between uploading and getting the verdict, as compared to no delay between getting the verdict and the download link, I think they just compress the image and see if it comes out smaller. Jul 8, 2013 at 21:06

2 Answers 2


Based on your reference to the ImageMagick convert method and quality parameter, it appears you're working with JPEG images. If that's the case, the EXIF information for JPEG images does not have a standard compression level tag.

However, ImageMagick appears to be able to obtain this information from the image's quantization tables using the identify command. So try this:

identify -verbose yourimage.jpg

And then you should be able to parse out the quality level from the standard output. For example:

Compression: JPEG
Quality: 80

I would just crush all of your images using a script like the one below which I use. Be sure to back up the images directory first. If any resultant images are smaller than the ones you were serving, then they weren't optimised!


# script for optimizing images in a directory (recursive)
# pngcrush & jpegtran settings from:
# http://developer.yahoo.com/performance/rules.html#opt_images

# pngcrush
for png in `find $1 -iname "*.png"`; do
    echo "crushing $png ..."
    pngcrush -rem alla -reduce -brute "$png" temp.png

    # preserve original on error
    if [ $? = 0 ]; then
        mv -f temp.png "$png"
        rm temp.png

# jpegtran
for jpg in `find $1 -iname "*.jpg"`; do
    echo "crushing $jpg ..."
    jpegtran -copy none -optimize "$jpg" > temp.jpg

    # preserve original on error
    if [ $? = 0 ]; then
        mv -f temp.jpg "$jpg"
        rm temp.jpg

pngcrush comes from here: http://pmt.sourceforge.net/pngcrush/
jpegtran comes from here: http://jpegclub.org/jpegtran/

Three notes:

  1. pngout has better compression on most files: http://advsys.net/ken/utils.htm [source]
  2. For JPEGs, spit them out in various quality settings and see what the lowest acceptable quality value is (it will vary by image and destination screen size)
  3. cwebp can probably do better on both jpegs and PNGs, but can only be used in Chrome and Opera (soon Firefox): https://developers.google.com/speed/webp/
  • thanks, would you find interesting the option -perfect for jpegtran? Jul 9, 2013 at 12:52
  • I left that out in case your build of jpegtran doesn't support it (I know that on GoDaddy shared hosts, for example, the version of jpegtran there dates from 1998 and thus doesn't support it). -perfect is primarily of use in the rotation operations where you have edges that don't fall on block boundaries. Jul 9, 2013 at 12:59
  • You may also be interested in the lossless crop'n'drop feature of the most recent builds: stackoverflow.com/a/17187580/760706 Jul 9, 2013 at 13:01
  • Interlaced in JPEG-lingo just means "progressive". Jul 9, 2013 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.