I have a batch of images I want to compress. There are hundreds, so I'd like to use CLI tools.

The images have the following characteristics.

$ identify 100.jpg 
100.jpg JPEG 639x426 639x426+0+0 8-bit sRGB 319KB

If I resize them with GIMP and export with these settings

enter image description here

I get a 20kB file of very acceptable quality.

$ identify c.jpg 
c.jpg JPEG 400x267 400x267+0+0 8-bit sRGB 20KB

If I resize it with Imagemagick's convert, however, as follows

$ convert 100.jpg -quality 50% -resize 400x267  c_im.jpg

I get a much larger file, without significant improvements in quality.

$ identify c_im.jpg 
c_im.jpg JPEG 400x267 400x267+0+0 8-bit sRGB 86.6KB

Even if I reduce the quality or the size further, I cannot get a file as small as what GIMP produces, unless I go so far that the image degenerates beyond recognition.

And even if I tick the EXIF and thumbnail boxes in GIMP, the size only grows up to about 43kB.

Is there a way to obtain the compression levels of GIMP with CLI tools, or in some automated manner?


I finally found a very helpful post here

The options I am using are these:

convert 100.jpg -strip -gaussian-blur 0.05 -quality 50% -resize 400x267  c_im.jpg

The strip option is really the key. From 85kB down to 16kB, just like that. Apparently it only removes comments and profiles, which I don't need.

The blur results in a slight size reduction but the loss in crispness is noticeable, so use at your discretion.

$ identify c_im.jpg 
c_im.jpg JPEG 400x267 400x267+0+0 8-bit sRGB 15.7KB 

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.