changing quality by giving KB/MB

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Locked
dcotto
Posts: 15
Joined: 2019-09-24T15:24:28-07:00
Authentication code: 1152

changing quality by giving KB/MB

Post by dcotto »

Is it possible to tell imagemagick to change the quality of a PNG, JPG, JPEG by giving it the KB/MB
for instance, i have want to convert the picture thats 210kb to around 100kb.. i give a command that says

convert 200kb.png -auto quality 100kb auto_quality.png
auto_quality.png size is around 110kb

and it finds the best quality around 100kb. it can be 110kb or 90kb just as long its around ~15kb plus or minus.

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: changing quality by giving KB/MB

Post by fmw42 »

Only for JPG. You can then use -define jpeg:extent={size}. See https://imagemagick.org/Usage/formats/#jpg_write. You should also use -strip to remove large amounts of meta data.

If on a Unix-like system, I have a bash Imagemagick script that will iterate the dimensions of the image until the file size reaches a desired amount for non-JPG (e.g. PNG, TIFF) files at my link below.

Please always provide your Imagemagick version and platform/OS when asking questions, since syntax may vary.

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: changing quality by giving KB/MB

Post by snibgo »

IM can do this for JPEG because it is fairly simple: decrease the "-quality" number and the filesize decreases.

PNG is more difficult because there is no direct relationship. The "-quality" number doesn't actually change quality, but the compression method.

The program "pngcrush" can find the best compression for a PNG image. But if that isn't as small as you want, you need to resize down.
snibgo's IM pages: im.snibgo.com

Locked