0
votes

I'm trying to convert an EPS file with an embedded TIFF that has a transparent background to a PNG using GhostScript. The problem that I am having is that the background of the TIFF image becomes white in the PNG. It looks like the following:

IncorrectPNG

When I export from Adobe Illustrator, it comes out correct:

CorrectPNG

I was reading that there is not transparency in EPS, only marked and unmarked areas. I was wondering if there was a call that I was missing that would create the PNG through Ghostscript similar to that of Illustrator? Or if there is any other alternative that doesn't just replace white with transparency through ImageMagick?

I am using Windows and have Ghostscript 9.25 installed. Here is the command (one of many) that I've tried:

-q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -sDEVICE=pngalpha -r300 -dEPSCrop NamePlatePNG.png NamePlate.eps


I can get the EPS file to you if needed. Any help would be appreciated, thanks!

UPDATE: Here is the EPS file (Hopefully this link works):

https://drive.google.com/open?id=1m4HHGLoPe0jdWkx1Oghe7ttiXPldZnJs

Also, I should have mentioned that the images I uploaded were just screenshots of the PNGs open in an image editor. The checkered portion is indeed fully transparent alpha channel. I was trying to easily accentuate the difference.

1
If your EPS file (or perhaps the embedded TIFF) is in CMYK colorspace, then Ghostscript will not process it correctly if it has transparency. So you need to convert it to sRGB colorspace when reading it in. In ImageMagick, I would do convert -colorspace SRG -density 300 input.EPS output.png. If that does not work, then post a link to your EPS file. Sorry, I do not know the argument for Ghostscript to convert to sRGB.fmw42
My command above has a typo. It should be -colorspace sRGB, not -colorspace SRG.fmw42
You can add -density 300 to the ImageMagick command if you want other than the default density of 72. So convert -colorspace sRGB -density 300 input.eps output.png. You may have to edit the policy.xml file to relax the security restriction on PDF, EPS, PS etc. See stackoverflow.com/questions/52861946/….fmw42
Thank you for your quick response! I did try this command through ImageMagick and it produces the same results as the Ghostscript command that I posted. I did post the the EPS file If you want to look at it. Thanks for your help.RockyRoad
I get the same result as you with only the top part transparent when I use convert -colorspace sRGB NamePlate.eps NamePlate.png. Sorry I do not know what is wrong. I get the same thing when opening in Photoshop. So perhaps it is the way the EPS file was created.fmw42

1 Answers

0
votes

Your file doesn't look like its transparent, it looks like its masked, possibly with a stencil mask, possibly chroma-keyed. Without seeing the file I can't tell for sure.

You are correct that PostScript (and hence EPS) doesn't support transparency, but it does support several features which have somewhat similar effects.

The color space is irrelevant, and in fact the only kind of 'transparency' supported in PostScript works when the color space is CMYK, but not when its RGB (and certainly not sRGB, which isn't even a PostScript color space, you have to manufacture it from CIEBasedABC)

As far as I can see the command line you are using is correct, but as I say I can't tell much without seeing the actual EPS program.

[EDIT] So the Ghostscript rendering is correct, that's what is in your EPS file, there is no transparency of any kind there. So how is Illustrator able to make a transparent PNG ? Well the answer is that Illustrator isn't using the PostScript part of the EPS file.

About 1/3 of the way through the EPS file you'll see a line which reads:

%AI9_PrivateDataBegin

What follows that is an Adobe Illustrator file format. When AI reads the file it finds that line, throws away the PostScript portion of the file, and reads the AI representation of the content from the portion of the file beginning with that comment.

Now stored somewhere in there will be the information that portions of the content are transparent. Although PostScript can't represent that, Illustrator's internal format can. So when you write a PNG file from Illustrator it knows that portion is transparent and writes it as such.

Ghostscript, however, is constrained by the PostScript portion of the file, it can't read the Illustrator native format, and so renders the image with a white background.

It 'might' be possible to save a different kind of EPS from Illustrator (level 3 instead of level 2 possibly, I notice this is a language level 2 EPS file) which duplicate the effect, but from what you have here, there isn't anything a standard PostScript interpreter can do which will give you the result you want.