开发者

Why a .png converted from a gnuplot postscript output, has transparent background?

I used gnuplot (4.2) to write a graph to a postscript file. But when I convert this .ps file to a .png file using the 'convert file.ps file.png' command, I get a png image which has no bac开发者_开发技巧kground (transparent).

Why does this happen, and how do I get a png image with a white background?


"Why does this happen?"

Two possible reasons combining:

First: Your PostScript input very likely doesn't contain any background. In effect, this is "transparent". When printing, this appears as usual. (Some PostScript files do have white backgrounds. And when printing, this still appears as usual. You only discover that when you try in retrospect to add some watermark into the file's "background" and when that seems not to work. In these cases, the watermark strokes are covered by a white area, which again is covered by the originally stroked PS content...)

Second: The convert a.ps a.png command doesn't do the job itself. It calls an external 'delegate' helper program, most likely Ghostscript. And Ghostscript has different ways to tweak its PNG output. You can query Ghostscript about all its output "devices" like so:

gs -h

Now limit the query to only lines containing PNG-related devices:

gs -h | grep png

You'll see there is a pngalpha output device. This one can output transparencies for PNG images.

Next, query convert about its full list of delegates:

convert -list delegate

You'll see a few dozen commands which convert uses behind your back in order to get its job done. Let's see, what commands it uses for PNG input or output handling:

convert -list delegate | grep -i png

You'll likely discover gs ... -sDEVICE=pngalpha ... commandlines for some conversion types.

"How do I get a png image with a white background?"

Try this:

convert a.ps -background white a.png


Pipitas already nicely explained why this is happening.

In order to solve your problem, i.e. to get a white background, use the -alpha off setting on the convert command line. Additionally, it is useful to control the resolution of the output using the -density x switch. Hence, you should try something like:

convert -density 300 -alpha off input.ps output.png

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜