Question

I am converting eps (Encapsulated PostScript) files to jpeg files with ghostscript. A sample command I use is:

gswin32.exe -sDEVICE=jpeg -dJPEGQ=100 -dNOPAUSE -dBATCH -dSAFER -r600x600  -dGraphicsAlphaBits=4 -dUseCIEColor  -dEPSCrop -sOutputFile=”a.jpeg” b.eps

The input eps files come with white backgrounds (I only have their clipping path). What I need to do is change this white background to another color in the output images, or it would be even better if I could make them transparent (output file format would be png). How can I do this?

Was it helpful?

Solution

never tried it myself but you should be able to convert your eps file into png by setting:

-sDEVICE=pngalpha

also the pngalpha device has a -dBackgroundColor option:

-dBackgroundColor=16#RRGGBB (RGB color, default white = 16#ffffff) For the pngalpha device only, set the suggested background color in the PNG bKGD chunk. When a program reading a PNG file does not support alpha transparency, the PNG library converts the image using either a background color if supplied by the program or the bKGD chunk. One common web browser has this problem, so when using on a web page you would need to use -dBackgroundColor=16#CCCC00 when creating alpha transparent PNG images for use on the page.

more details here: Details of Ghostscript output devices see section 3.1. PNG file format

OTHER TIPS

After you've obtained your (white background) images from Ghostscript, you could use ImageMagick's convert or GraphicMagick's gm convert commands to change the white to transparent background:

convert -background transparent my.png my_transp.png

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top