Converting PDF to PNG with transparency and resizing

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
yervand
Posts: 5
Joined: 2013-06-24T14:45:51-07:00
Authentication code: 6789

Converting PDF to PNG with transparency and resizing

Post by yervand »

I have a PDF file which I would like to convert to a png format and create everything white as transparent on there. Along with this I also need to resize the original file size by a specific value and make it high quality. Sounds like a lot i know. I put the -fuzz command thinking that it allows for not perfect white in the background to still be detected as white. Is this correct about the fuzz function

Basically i have a PDF in CMYK format 300 DPI.

I need to scale the PNG by 2.2 x original PDF size in 300 DPI

So if PDF is 3x4 I need the png to be 6.6x8.8

So far here is my code

Code: Select all

exec('convert -density 300 -colorspace rgb {$pdf_file}' -channel rgba -fuzz 600 -transparent "#ffffff" {$png_file});
This works great with the transparency and the quality but the size is completely off. I have tried putting in the -resample command but it just makes it way too big.

Is there a way to keep the quality high and be able to have the png at a specific size ?

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

Re: Converting PDF to PNG with transparency and resizing

Post by fmw42 »

If your PDF is cmyk, you should convert to sRGB before processing with color changes.

You can use supersampling to maintain high quality.

try

convert -colorspace sRGB -density 288 image.pdf -resize 25% -fuzz 600 -transparent "#ffffff" result.png

what we are doing is multiplying nominal density of 72 x 4 = 288 and then resizing by 1/4 = 25%
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting PDF to PNG with transparency and resizing

Post by snibgo »

If the natural DPI of the PDF is 300, and you want 2.2 times as many pixels on each dimension, I suggest you try "-density 660", with no resize or resample.
snibgo's IM pages: im.snibgo.com
Post Reply