Imagemagick -quality 85 doesn’t work

imagemagick

I run mogrify to compress a JPEG image to 85% quality:

$ ls -lah Screenshot.jpg
-rw-rw-r--.  1 USER GROUP 440K May 24 12:10 Screenshot.jpg
$ mogrify -compress JPEG Screenshot.jpg -quality 85
$ ls -lah Screenshot.jpg
-rw-rw-r--.  1 USER GROUP 441K May 24 12:10 Screenshot.jpg

The size doesn't shrink. Yet if I open the image in Gimp and save at 85% quality, the size does shrink:

ls -lah Screenshot.jpg
-rw-rw-r--.  1 USER GROUP 135K May 24 12:11 Screenshot.jpg

Why doesn't ImageMagick compress the JPEG image to 85%? I'm using ImageMagick-6.6.4.1-15.fc14.i686 on Fedora.

Best Answer

It looks like the relative ordering of modifier arguments (-quality NN) and filenames does matter here, almost like it's doing what it's told in a very, very simplistic way.

: cez@rhk; !ls
ls -lh Screenshot.jpg 
-rw-r--r--  1 cez  staff   1.3M  5 24 19:20 Screenshot.jpg
: cez@rhk; mogrify -verbose -monitor -compress JPEG Screenshot.jpg -quality 10
load image[Screenshot.jpg]: 1079 of 1080, 100% complete
Screenshot.jpg JPEG 1920x1080 1920x1080+0+0 8-bit DirectClass 1.335MB 0.120u 0:05.680
save image[Screenshot.jpg]: 1079 of 1080, 100% complete
Screenshot.jpg JPEG 1920x1080 1920x1080+0+0 8-bit DirectClass 1.327MB 0.240u 0:02.960
: cez@rhk; 

So, the first time we run mogrify, we specify the -quality argument after the filename, and so it doesn't know that the quality specifier should apply to that image.

: cez@rhk;mogrify -verbose -monitor -compress JPEG -quality 85 Screenshot.jpg 
load image[Screenshot.jpg]: 1079 of 1080, 100% complete
Screenshot.jpg JPEG 1920x1080 1920x1080+0+0 8-bit DirectClass 1.341MB 0.100u 0:00.119
save image[Screenshot.jpg]: 1079 of 1080, 100% complete
Screenshot.jpg JPEG 1920x1080 1920x1080+0+0 8-bit DirectClass 459KB 0.190u 0:00.200
: cez@rhk; 

Conversely, if we specify the quality setting before the image filename, it'll save the image with more compression, reducing the filesize.

Related Question