Using -size and -quality in the same command

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?".
Post Reply
virtual

Using -size and -quality in the same command

Post by virtual »

I'm converting a PDF into PNG's using the following command:

Code: Select all

exec("convert -resize 500x700! -quality 50 input.pdf output.png");
However, the quality always seems to be set to 100 (the file size is 280kb!). Is there a way I can get the output.png to be < 100kb whilst also resizing?

Thanks!
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Using -size and -quality in the same command

Post by Bonzo »

Version 6 should read the image in first, -strip removes all EXIF data etc. -thumbnail removes all EXIF data except the colour profile on earlier versions.

Try:

Code: Select all

exec("convert  input.pdf -resize 500x700! -strip -quality 50 output.png");
You are saving as a png which has more colours; a smaller filesize would be jpg. Try them both and see the file size difference.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using -size and -quality in the same command

Post by fmw42 »

you should set the density before reading in the pdf. also see http://www.imagemagick.org/script/comma ... hp#quality for what quality does with PNG. Also see http://www.imagemagick.org/Usage/formats/#png_quality

If you want high quality png, then use supersampling by setting the density high and resizing to compensate, e.g.

convert -density 288 image.pdf -resize 25% result.png

density 288 = 4*72 dpi, so use 25% for resizing to get back to the same size. Reduce further if you desire.
virtual

Re: Using -size and -quality in the same command

Post by virtual »

Fantastico! Thanks guys, I'll give that a go tomorrow. Great help!
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Using -size and -quality in the same command

Post by anthony »

virtual wrote:I'm converting a PDF into PNG's using the following command:

Code: Select all

exec("convert -resize 500x700! -quality 50 input.pdf output.png");
However, the quality always seems to be set to 100 (the file size is 280kb!). Is there a way I can get the output.png to be < 100kb whilst also resizing?

Thanks!
-quality 50 is meaningful only to JPEG images. for PNG -quality uses very different values.
The first digit is compression with '9' as the highest, the second digit is encoding method and the best method depends on the type of image (real life, cartoon-like, etc)

To find the best compression for PNG look at "OptiPNG", For 8-bit (color table or palette) PNG whcih is smaller but lossy (whcih as you are resizing is obviously not an issue), you can also look at "pngng". See IM examples, Common File Formats, PNG non-IM PNG tools...
http://www.imagemagick.org/Usage/formats/#png_non-im
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply