ImageMagick: scale JPEG image with a maximum file-size

后端 未结 2 650
不思量自难忘°
不思量自难忘° 2020-11-29 20:41

I have a number of JPEG pictures which I would like to scale down. Another requirement is that the file size should not be larger than say 300kByte.

Is that possible

2条回答
  •  一整个雨季
    2020-11-29 21:00

    To restrict the resulting image to a maximum file size, you can use the commandline parameter -define jpeg:extent=max_value, like this:

    convert original.jpeg -define jpeg:extent=300kb output.jpg
    convert original.jpeg -define jpeg:extent=300kb -scale 50% output.jpg
    convert original.jpeg -define jpeg:extent=300kb [...other options...] output.jpg
    

    Note, this will not always work to match the exact size you wanted. You may have asked for 40kb output size, where input is 300kb, and get a result of 48kb.


    (Update/Clarification: Output file size may be a bit lower or higher than your file requested size.)

提交回复
热议问题