How can I extract color values from an EPS file?

后端 未结 2 1607
无人及你
无人及你 2021-01-16 01:23

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

相关标签:
2条回答
  • 2021-01-16 02:00

    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

    0 讨论(0)
  • 2021-01-16 02:19

    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.

    0 讨论(0)
提交回复
热议问题