3

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.

LanceBaynes
  • 40,135
  • 97
  • 255
  • 351

2 Answers2

5

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.

C. Storey
  • 306
  • I just feel it's worth defending ImageMagick's honor by pointing out that the argument-order dependency of its tools isn't it being "simplistic", but rather "powerful". ImageMagick's tools all operate on a chained basis, and allow multiple operations on the same command line. So you could do something like convert image.png \( +clone -quality 85 -write image.jpg +delete \) -quality 50 -resize x200 image_thumb.jpg to convert a PNG file to an 85%-quality JPEG and a 50%-quality thumbnail all in one go. That's why argument order matters. – FeRD Jun 05 '18 at 12:02
0

Not exactly the same issue but I was stuck on this for ages. Turns out the size wasn't shrinking because all the file size was in the metadata and adding -strip to the command cut down the size.

Qwertie
  • 1,264