如何使用免费软件或命令行实用工具调整EPS文件的大小 [英] How to resize an EPS file with free software or command line utility

查看:385
本文介绍了如何使用免费软件或命令行实用工具调整EPS文件的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Matlab生成EPS(封装的PostScript)文件.我想调整这些文件的大小,以便它们以与生成的大小不同的大小呈现.理想情况下,我想以英寸或厘米为单位指定调整大小的尺寸.是否可以使用免费软件或命令行实用程序来执行此操作?

I use Matlab to generate EPS (Encapsulated PostScript) files. I would like to resize these files so they render at a different size than they are generated. I would like to specify the resized dimensions in inches or centimeters, ideally. Is there an option for doing this using free software or a command line utility?

我正在寻找与OSX兼容的产品,但会选择Windows.我知道EPSViewer.org,但它仅以像素为单位工作,并且将尺寸限制为成比例.

I am looking for something compatible with OSX, but would settle for Windows. I am aware of EPSViewer.org but it only works in pixels and constrains the dimensions to be proportional.

推荐答案

您可以使用 Ghostscript (您需要的免费软件+命令行实用程序).

You can use Ghostscript (a Free software + command line utility as you want).

它可用于Linux,Windows和Mac OS X.

It is available for Linux, Windows and Mac OS X.

确保具有最新的Ghostscript版本(v9.15或更高版本),其中包括eps2write设备. (用gs -h | grep --color=auto -E '(epswrite|eps2write)'检查您拥有哪个.)

Make sure to have the most recent Ghostscript version (v9.15 or later) which includes the eps2write device. (Check with gs -h | grep --color=auto -E '(epswrite|eps2write)' which one you have.)

预编译的二进制文件可在此处用于Linux和Windows:

Pre-compiled binaries are available for Linux and Windows here:

然后,要在保持宽高比的同时将input.eps缩放到50%,可以运行以下命令:

Then, to scale your input.eps to 50% while preserving the aspect ratio, you can run this command:

gs                                                \
  -o scaled.eps                                   \
  -sDEVICE=eps2write                              \
  -c "<</Install {0.5 0.5 scale}>> setpagedevice" \
  -f input.eps

(对于Windows,将gs替换为gswin32c.exegswin64c.exe.)

(For Windows, replace gs by gswin32c.exe or by gswin64c.exe.)

-c "..." 命令行参数使您可以添加PostScript代码段,这些代码段将在Ghostscript处理输入文件时执行.在上面的示例中,它缩放了输入页面.

The -c "..." command line parameter allows you to add PostScript code snippets which will be executed when Ghostscript processes the input file. In the above example it scales the input page.

这里证明缩放有效.通过使用-sDEVICE=bbox运行Ghostscript,您将获得EPS文件的 计算 边界框,它们定义了将绘制实际像素的矩形:

Here is proof that the scaling worked. By running Ghostscript with -sDEVICE=bbox you get the computed BoundingBoxes of the EPS files, which define the rectangles where actual pixels will be painted:

gs -q -o -sDEVICE=bbox input.eps 
  %%BoundingBox: 41 19 585 831
  %%HiResBoundingBox: 41.990975 19.997999 584.027982 830.009014

gs -q -o -sDEVICE=bbox scaled.eps 
  %%BoundingBox: 20 9 293 416
  %%HiResBoundingBox: 20.991023 9.990000 292.013991 415.008972

您还可以使用它以液体"方式缩放,而无需通过给scale运算符提供不同的参数来保持宽高比.不幸的是,我无法避免您自己计算相应的数字. (我们也可以在PostScript中做到这一点,并提供一个命令行,您可以在其中插入所需的尺寸,如 inch ,但这会使命令行太长.问问是否仍然要这样做,然后我相应地更新此答案...)

You can also use it to scale in a "liquid" way, without preserving aspect ratios by giving to different parameters to the scale operator. Unfortunately, I cannot spare you from calculating the respective numbers by yourself. (We could do it in PostScript too, and give a command line where you would insert your required dimensions as inch, but that would make the command line too long. Ask if you want it anyway, then I update this answer accordingly...)

我用它来将EPS从A4纵向缩放到A4横向:

I used this to scale an EPS from A4 portrait to A4 landscape:

gs                                                      \
  -o A4-landscape.eps                                   \
  -sDEVICE=eps2write                                    \
  -c "<</Install {1.4151 0.7066 scale}>> setpagedevice" \
  -f A4-portrait.eps

以下是我使用的输入和输出文件的屏幕截图:

Here are screenshots of the input and output files I used:

  • A4-portrait.eps(输入)正确.
  • 剩下
  • A4-landscape.eps(输出).
  • A4-portrait.eps (input) is right.
  • A4-landscape.eps (output) is left.

 

对于OS X,您可能会想通过 MacPorts 来获取Ghostscript. .一旦完成了基本的MacPorts安装,就可以轻松完成:

For OS X, you may be tempted to get Ghostscript through MacPorts. Once you have the base MacPorts installation, it would as easy as:

sudo port -pf install ghostscript

以安装它(包括所有依赖项).

to install it (including all dependencies).

但是,请注意: MacPorts当前仅提供Ghostscript v9.10.该版本尚未包括eps2write设备.如果您使用的是GS 9.10,则只能使用epswrite,但是这样做的缺点是只能发出PostScript Level 1,这可能会使生成的缩放后的EPS严重像素化.

However, be warned: MacPorts currently gives you only Ghostscript v9.10. That version does not yet include the eps2write device. If you use GS 9.10, you can only use epswrite -- but this has the disadvantage to only emit PostScript Level 1, which may heavily pixelate your resulting scaled EPS.

这篇关于如何使用免费软件或命令行实用工具调整EPS文件的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆