Vector to PNG with alpha transparency problems

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
rossmeissl

Vector to PNG with alpha transparency problems

Post by rossmeissl »

Hello,

I'm having trouble converting a vector file to PNG while preserving alpha transparency. I've tried every possible combination of options I could find on the board, and still no luck.

I've tried starting with all 3 of these file types: The EPS and PDF always come out with a white background, despite trying the "-colorspace RGB," "-channel RGBA," and "-background none" tricks I have found here.

Here are some examples:
The closest I'm getting is with the SVG, but the resulting PNG inexplicably has a black background with 50% transparency behind the motorcycle.

Thanks in advance.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Vector to PNG with alpha transparency problems

Post by magick »

Type
  • convert -colorspace RGB motorcycle.eps motorcycle.png
    identify -verbose motorcycle.png
We get alpha statistics that show levels of transparency:
  • alpha:
    min: 53713 (0.819608)
    max: 65535 (1)
    mean: 65525.1 (0.999848)
    standard deviation: 301.241 (0.00459664)
    kurtosis: 1034.93
    skewness: 31.6121
Do you get the same distribution for alpha?
rossmeissl

Re: Vector to PNG with alpha transparency problems

Post by rossmeissl »

Code: Select all

    alpha:
      min: 53713 (0.819608)
      max: 65535 (1)
      mean: 65525.1 (0.999848)
      standard deviation: 301.241 (0.00459664)
      kurtosis: 1034.93
      skewness: 31.6121
Full output is at http://pastie.org/484496
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Vector to PNG with alpha transparency problems

Post by magick »

It appears that the conversion from EPS to PNG is preserving transparency as expected.
rossmeissl

Re: Vector to PNG with alpha transparency problems

Post by rossmeissl »

Thanks for helping me with this!

Unfortunately, here's the output image that resulted from the commands you had me run:

Image
http://banjo.brighterplanet.com/andy/motorcycle.png

As far as I can tell, it's not transparent.
rossmeissl

Re: Vector to PNG with alpha transparency problems

Post by rossmeissl »

For comparison, when I use Illustrator's Save for Web, I get this:

Image
http://banjo.brighterplanet.com/andy/mo ... narrow.png
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Vector to PNG with alpha transparency problems

Post by magick »

If the image is not rendered correctly, the bug is in Ghostscript or the Ghostscript pngalpha device. ImageMagick delegates Postscript rendering to Ghostscript with this command line:
  • "gs" -q -dQUIET -dPARANOIDSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72" -g121x87 "-sOutputFile=/tmp/magick-XX1HoH3Z" "-f/tmp/magick-XXlMwZ7j" "-f/tmp/magick-XXBA8lcE"
rossmeissl

Re: Vector to PNG with alpha transparency problems

Post by rossmeissl »

Any chance you could try that convert command on motorcycle.eps and make sure I'm not just crazy?

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

Re: Vector to PNG with alpha transparency problems

Post by fmw42 »

I downloaded your motorcycle.eps and did the following on IM 6.5.4-7 Q16 Mac OSX Tiger (with gs 8.61) and got:

convert motorcycle.eps motorcycle.png
Unknown device: bmpsep8
Unrecoverable error: undefined in .uninstallpagedevice
Operand stack:
defaultdevice
Unknown device: bmpsep8
Unrecoverable error: undefined in .uninstallpagedevice
Operand stack:
defaultdevice
convert: Postscript delegate failed `/var/tmp/magick-DWKZZyaR': No such file or directory @ ps.c/ReadPSImage/741.
convert: motorcycle.eps: invalid TIFF directory; tags are not sorted in ascending order. `TIFFReadDirectory' @ tiff.c/TIFFWarnings/525.

But it produces a partially transparent image:
Image

But if I do
convert -colorspace rgb motorcycle.eps motorcycle2.png

I get a white background:
Image
rossmeissl

Re: Vector to PNG with alpha transparency problems

Post by rossmeissl »

Interesting. Dropping the colorspace argument like you did in your first test results in a white background for me, but runs without errors.

Does anybody have a test EPS with alpha transparency that has been verified to produce a correct PNG? I'd love to try it on my machine.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Vector to PNG with alpha transparency problems

Post by fmw42 »

I had this same problem/error in viewtopic.php?f=1&t=13753&hilit=bmpsep8 and viewtopic.php?f=3&t=13723&p=46762&hilit=bmpsep8#p46762

but so far no one has told me how to correct or avoid that error message. There must be some configuration that I need to do to fix it. Perhaps a GS upgrade. But I don't know for sure.
rossmeissl

Re: Vector to PNG with alpha transparency problems

Post by rossmeissl »

For any Googlers landing here: rsvg performs SVG -> PNG-24 (with alpha transparency) conversions flawlessly.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Vector to PNG with alpha transparency problems

Post by magick »

Use this command to perform SVG -> PNG-24 (with alpha transparency) conversions flawlessly:
  • convert -background none motorcycle.svg motorcycle.png
Not sure why it did not work for you. We're using ImageMagick 6.5.2-7, the current release.
rossmeissl

Re: Vector to PNG with alpha transparency problems

Post by rossmeissl »

Unfortunately, this is what I get from that command:

Image
http://banjo.brighterplanet.com/andy/motorcycle-12.png
Post Reply