Convert from eps with transparent background to png

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
mithrandir77

Convert from eps with transparent background to png

Post by mithrandir77 »

Hi All,

this is my first post on this forum, even if I am using imagemagick since quite 5 years ago.
I need to convert a vectorial image (eps) to png format and a found that eps image format is supported by imagemagick.

But if I try to convert an eps image with a transparent background, I found that the resulting png image has a white background instead of a transparent one as expected.

I looked for this problem along your forum and I found no post about, and every convert option about background color has not effect on my resulting images.

The convert command I am using is the following (simple) one:

/usr/bin/convert dial_example.eps step0.png

Does anyone know how to make convert keep the original transparent background on the resulting image?

Thanks a lot to everyone :-)

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

Re: Convert from eps with transparent background to png

Post by fmw42 »

this works for me with a transparent eps that is cmyk

convert -colorspace rgb test.eps test.png

what version of IM are you using? if old, perhaps upgrade.

also you could post a link to your image and others could test it.
mithrandir77

Re: Convert from eps with transparent background to png

Post by mithrandir77 »

Hi fmw42,

thank you very much, it works fine!

So if I understood well, if a transparent eps cmyk, I have to set colorspace to rgb to mantain its transparent background.

How can I understand the image colorspace before converting it?

Another question: I am trying also to convert a vectorial ".ai" image, which is rgb, but I can't get a transparent background even using different colorspace.

Following the links to eps and ai test vector images I am using

http://mithrandir77.homelinux.net/vecto ... example.ai
http://mithrandir77.homelinux.net/vecto ... xample.eps

Thanks a lot for your help

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

Re: Convert from eps with transparent background to png

Post by fmw42 »

I don't really know too much about vector formats. I am told you can change the device in the delegates.xml file so that you don't need to change to rgb. But I don't know what is needed. Perhaps one of the IM folks can clarify further.
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Convert from eps with transparent background to png

Post by Drarakel »

I am struggling with this myself for a while...

The "-colorspace RGB" parameter will give you transparency with EPS files, yes.
As fmw42 said, you have to edit the delegates.xml to get transparency with PDF files, too. You need to edit the line '<delegate decode="ps:color"...'. There you have to change '-sDEVICE=pnmraw' to '-sDEVICE=pngalpha'. If you edit the line '<delegate decode="ps:cmyk"...' the same way, you also don't have to use "-colorspace RGB" anymore. :) (Another possibility would be to create a new delegate for this.)
Now if you have multi-page PDFs, with "pngalpha" you will only get an output for the first page. That's the only disadvantage AFAIK.

If the main goal is to get the alpha layer, this will probably suffice.
But a small warning: If you also need correct colors (when you have real CMYK colors in the input files), this won't suffice. Getting correct colors AND transparency with ghostscript (with one command), that's nearly impossible. At least I don't know an easy solution.
mithrandir77

Re: Convert from eps with transparent background to png

Post by mithrandir77 »

Thanks a lot both for your help.

First, I understood that my knowledge about image formats and conversion is very little at the moment :-)
However, I can't modify delegates.xml config file, because the service I am developing will be hosted on an external hosting service.
So I think that I have to limit my service to convert a single eps image in png format.

Thanks a lot again for your suggestions, I keep these in mind going on investigating
:)
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Convert from eps with transparent background to png

Post by Drarakel »

If you want to try it with PDFs/AIs eventually and you can't alter the delegates of ImageMagick, you can probably execute a Ghostscript command (instead of executing an ImageMagick command which will itself execute Ghostscript). As a starting point, you could use something like this:
gs -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=2 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dUseCIEColor -r72x72 -sOUTPUTFILE=output.png input.ai
(The '-dUseCIEColor' parameter is good for CMYK files. You won't always get perfect colors - but at least transparency. :))
mithrandir77

Re: Convert from eps with transparent background to png

Post by mithrandir77 »

Drarakel wrote:If you want to try it with PDFs/AIs eventually and you can't alter the delegates of ImageMagick, you can probably execute a Ghostscript command (instead of executing an ImageMagick command which will itself execute Ghostscript). As a starting point, you could use something like this:
gs -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=2 -sDEVICE=pngalpha -dTextAlphaBits=4 -dGraphicsAlphaBits=4 -dUseCIEColor -r72x72 -sOUTPUTFILE=output.png input.ai
(The '-dUseCIEColor' parameter is good for CMYK files. You won't always get perfect colors - but at least transparency. :))

Good, I will try :-)

I will keep you updated about
Gbhatia
Posts: 1
Joined: 2017-02-21T05:20:11-07:00
Authentication code: 1151

Re: Convert from eps with transparent background to png

Post by Gbhatia »

Hi ,

I am able to convert my EPS to PNG with white text on it . I have set colorspace to RGB . But I am getting one issue, I am getting some blackoutline on white text after converting to png.

If anybody is having some solution please suggest.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert from eps with transparent background to png

Post by snibgo »

What version of IM and Ghostscript? If either are old, try an upgrade.

Otherwise, please post sample inputs and outputs. You can upload to somewhere like dropbox.com and paste the URLs here.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert from eps with transparent background to png

Post by fmw42 »

For current versions of IM use -colorspace sRGB not -colorspace RGB.

Please post your exact command line.

In the future, please do not tack onto an old post. Please start a new one with your exact problem.

Please, always provide your IM version and platform when asking questions, since syntax may differ. Also provide your exact command line and if possible your images.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at viewtopic.php?f=1&t=9620

For novices, see

viewtopic.php?f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
Post Reply