Reducing Image file sizes with ImageMagick

For JPEG Images, the following options reduce image size without quality loss (Removes all EXIF):

-strip -interlace Plane -define jpeg:dct-method=float

If the above options are not enough, try with reducing quality and sampling-factor:

-sampling-factor 4:2:0 -quality 85

If it’s an option, reducing the image resolution is also very effective:

-resize [width] (calculates height automatically)
-resize x[height] (calculates width automatically)
-resize [width]x[height]
-resize [percentage]%

Finally, a little gaussian-blur can help compress the image even further, but will result in a slightly blurred image:

-gaussian-blur 0.05

When resizing the image, the -density option might be useful. It has no effects on file size or image quality, but it sets the image dpi value in the image file which may be used by some programs such as photoshop or when printing the image.

Full working example:

$ magick input.jpg -strip -interlace Plane -define jpeg:dct-method=float -sampling-factor 4:2:0 -density 192 -resize 1200 -gaussian-blur 0.05 output.jpg

References:


Posted

in

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *