1

A JPEG image can be reduced in quality and, thus, in file size using ImageMagick in a way such as the following:

convert -quality 85% image.jpg image_small.jpg

How can the quality of an image be reduced such that the resulting image is below a certain file size (e.g. 3 MB)? A scenario in which this would be useful would be preparing a large number of images for upload to a site like Imgur.

d3pd
  • 6,679
  • 18
  • 56
  • 111

1 Answers1

3

I thought there was a post about this last week but can not find it. There was another here: ImageMagick: scale JPEG image with a maximum file-size

Anyway you want to use: -define jpeg:extent=400KB https://www.imagemagick.org/script/command-line-options.php#define

Out of interest your code is wrong as the input comes after convert and your quality goes before the output image.

So you want something like this:

convert image.jpg -define jpeg:extent=3000KB image_small.jpg

If you have an old version of Imagemagick it may not work that is why it is always good to include your imagemagick version in your question. The results are a bit hit and miss on exact filesize.

Community
  • 1
  • 1
Bonzo
  • 4,836
  • 1
  • 15
  • 25