问题
I'm trying to find all fill and stroke values used in an EPS file. I can parse the file, I just can't figure out how color values are defined in the EPS postscript section. I have converted the file to SVG (using ghostscript) and I can get the hex values, but an EPS to SVG conversion with a gradient produces files 20x the size. Is there a standard format for color values in postscript that I can extract from an EPS file?
回答1:
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.
回答2:
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
来源:https://stackoverflow.com/questions/16680747/how-can-i-extract-color-values-from-an-eps-file