如何从EPS文件中提取颜色值

如何从EPS文件中提取颜色值

本文介绍了如何从EPS文件中提取颜色值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试查找EPS文件中使用的所有填充和描边值。我可以解析文件,只是无法弄清楚EPS后记部分中的颜色值是如何定义的。我已经将文件转换为SVG(使用ghostscript),并且可以获取十六进制值,但是使用渐变将EPS转换为SVG会生成20倍大小的文件。我可以从EPS文件中提取的脚本中的颜色值是否有标准格式?

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?

推荐答案

PostScript是一种编程语言,不是简单的文件格式,因此没有简单的方法来确定程序中正在发生什么。

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.

在PostScript中,渐变很可能被定义为平滑阴影,

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).

您可以使用PostScript这一事实,因为它是SVG中没有等效功能的高级构造,因此将被渲染为图像。通过重新定义基本操作并使用它来获取所需信息是一种编程语言。例如,要查找笔划使用的颜色,您可以执行以下操作:

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

当然,您需要准备应对在PostScript中具有多种可能的色彩空间;灰色,RGB,CMYK,分隔,DeviceN,CIEBasedA,CIEBasedABC,CIEBasedDEF,CIEBasedDEFG,索引和图案。

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.

可能您不需要;不需要知道原始值,我猜这是真的,因为我认为转换为SVG会将所有颜色都转换为RGB,所以也许您只想要RGB等效项。在这种情况下,您可以简单地使用:

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.

这篇关于如何从EPS文件中提取颜色值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 22:09