Page 1 of 1

Converting PDF to PNG with transparency and resizing

Posted: 2013-09-12T08:05:05-07:00
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

Re: Converting PDF to PNG with transparency and resizing

Posted: 2013-09-12T09:46:55-07:00
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%

Re: Converting PDF to PNG with transparency and resizing

Posted: 2013-09-13T09:51:14-07:00
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.