How to change background color of eps file when converting it to jpeg or png

I am converting eps (Encapsulated PostScript) files to jpeg files using ghostscript. I use the following command:

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

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

+4
source share
2 answers

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

 -sDEVICE=pngalpha 

also the pngalpha device has the -dBackgroundColor parameter:

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

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

+1
source

After you have received images on a white background from Ghostscript, you can use the ImageMagick convert or GraphicMagick gm convert commands to change white to a transparent background:

convert -background transparent my.png my_transp.png

0
source

All Articles