Page 1 of 1

Background transparence on PNG from PDF

Posted: 2009-04-01T00:51:08-07:00
by webid
Hi !

I try to convert a PDF file to a PNG with background transparence ...
After verification, the PDF file has a transparent background, but when I convert him on a PNG, i have a white background.

I try this command, but the background is still white :

Code: Select all

convert test.png -background none test.png
Can you propose some examples in order to keep the background white ?

Thank's.

ps : Sorry for my English, I'm French and I don't control this language completely ... :oops:

Re: Background transparence on PNG from PDF

Posted: 2009-04-02T10:49:00-07:00
by fmw42
convert test.png -fuzz XX% -transparent white test.png

XX is the fuzz percent for finding colors close to white and then making them transparent.

See -fuzz, -transparent at http://www.imagemagick.org/script/comma ... ptions.php
also for color specification see http://www.imagemagick.org/script/color.php

Re: Background transparence on PNG from PDF

Posted: 2009-04-07T02:09:17-07:00
by webid
Thank you. I use this command :

Code: Select all

convert test.pdf -fuzz 100% -transparent white test.png
My PNG is transparent :)

Re: Background transparence on PNG from PDF

Posted: 2009-06-08T19:33:15-07:00
by jon@techvalidate.com
Hi. I have a similar use case that perhaps someone more experienced with IM can help me with.

I also have a PDF with a transparent background that I need to convert to PNG with the original transparency intact. However, in my case, just setting the transparent color to white won't work -- there are drop shadows on elements in the PDF that I need to preserve, with transparency. So, just converting white pixels to transparent would give me white fringes on objects in the image, even if I use a bit of fuzz.

I have tried and failed to find the magic incantation to tell IM to treat transparent portions of the input PDF as transparent in the output PNG. Have tried various settings for -background and -alpha, to no avail.

Any help would be greatly appreciated.

Btw, I am using IM 6.3.9 on MacOS X 10.5.7.

Re: Background transparence on PNG from PDF

Posted: 2009-06-08T20:07:09-07:00
by anthony
Please note that using -fuzz XX -transparent is not a 'good' solution. All it does is replace any instance of pure or near pure white with transparency.

The problem with this is that images are rarely that simple. Usally text and drawings have edges that are a mix of the background and the object itself. that is they contain mixed colors to 'anti-alias' or make the displayed objects looks 'smoother' to the human eye.

As a result the image will have 'stair-cased edges', or 'white halo effects' around them.

However if you read the image in at a higher resolution, do the color replacement, and then re-sample the image back to the desired resolution (typically 72 or 90 dpi), then much of thos problems will be fixed by the resize operator 'cleaning up' the edges.

The better solution would be to somehow actually get IM to get the Ghostscript delegate to render the PDF file properly on transparency. Usually that is don by setting -colorspace RGBA before 'reading' the PDF page.

Try reading the PDF like this....

Code: Select all

convert  -background none -colorspace RGBA test.pdf  test.png
Let us know how it goes.

This does not always work, as the PDF may actually draw white, such as in a diagram on the page, but it should work most of the time.