开发者

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

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?


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜