How can I extract color values from an EPS file?

大城市里の小女人 提交于 2019-12-01 13:40:17
KenS

PostScript is a programming language, not a simple file format, so there is no simple way to determine what is going on in the program.

A gradient may well be defined as a smooth shading in PostScript, which is a high level construct with no equivalent in SVG, so it will be rendered as an image (hence the explosion in size).

You can use the fact that PostScript is a programming language by redefining the basic operations, and using that to get the information you want. For example, to find the colour being used for a stroke you might do :

/OriginalStroke /stroke load def
/stroke {
(Current colour space = ) print currentcolorspace == flush
(current colour = ) print mark currentcolor counttomark -1 1 { -1 roll 20 string cvs print ( ) print} for flush pop
OriginalStroke
} bind def

Of course you will need to be prepared to cope with the rich variety of possible colour spaces in PostScript; Gray, RGB, CMYK, Separation, DeviceN, CIEBasedA, CIEBasedABC, CIEBasedDEF, CIEBasedDEFG, Indexed and Pattern.

Possibly you don';t need to know the original values, I'm guessing this is true because conversion to SVG will, I think, convert all colours to RGB, so perhaps you only want the RGB equivalents. In which case you could simply use:

(current colour in RGB = ) print currentrgbcolor 3 -1 roll == exch == == flush

I don't know how you wold handle a fill with a Pattern colour though :-)

Perhaps if you explained why you want to know this it would be easier to help.

the size of the bit image should not really matter if all you do is get a histogram and throw it away:

 pstopnm -stdout file.ps | ppmhist

I assume everyone has netpbm...netpbm.sourceforge.net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!