Mobile app version of vmapp.org
Login or Join
Karen161

: Check if an image is already optimized for the web 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 :))

@Karen161

Posted in: #Images #Linux #Optimization #PageSpeed

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.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Karen161

2 Comments

Sorted by latest first Latest Oldest Best

 

@Bryan171

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!

#!/bin/sh

# script for optimizing images in a directory (recursive)
# pngcrush & jpegtran settings from:
# developer.yahoo.com/performance/rules.html#opt_images
# pngcrush
for png in `find -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"
else
rm temp.png
fi
done

# jpegtran
for jpg in `find -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"
else
rm temp.jpg
fi
done


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

Three notes:


pngout has better compression on most files: advsys.net/ken/utils.htm [source]
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)
cwebp can probably do better on both jpegs and PNGs, but can only be used in Chrome and Opera (soon Firefox): developers.google.com/speed/webp/

10% popularity Vote Up Vote Down


 

@Ann8826881

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
...

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme