1

我正在尝试生成一个 eps 以包含在一个 LaTeX 文档中,该文档的边框为图形内容周围的 1 像素空白。该图是我使用 postscript 终端使用 gnuplot 制作的图:

set terminal postscript enhanced eps color colortext 14 size 19cm,15cm font 'Courier-Bold,30'

这个数字有很多空白,我想把它减少到 1 个像素。我可以使用该epstool实用程序将其裁剪为零空白边框:

epstool --bbox --copy input.eps output.eps

如果不手动编辑 .eps 文件来更改边界框,我找不到添加 1 个像素的空白的方法。-l像( --loose)这样的实用程序的一个选项会很好ps2eps,它完全符合我的要求。

4

2 回答 2

2

(最后一分钟添加:刚刚看到你的答案,所以你可能不需要这个)

这很容易做到awk

awk '/^%%(HiRes)?BoundingBox:/{print $1, $2-1, $3-1, $4+2, $5+2;next}{print}'
于 2012-11-26T17:42:08.550 回答
0

我最终编写了一个 python 函数来进行边界框扩展:

def expand_boundingbox(epsfile, outfile):
    with open(epsfile, 'r') as f:
        with open(outfile, 'w') as o:
            lines = f.readlines()
            for line in lines:
                line = line.split()
                if line[0] == '%%BoundingBox:':
                    line[1] = str(int(line[1]) - 1)
                    line[2] = str(int(line[2]) - 1)
                    line[3] = str(int(line[3]) + 2)
                    line[4] = str(int(line[4]) + 2)
                if line[0] == '%%HiResBoundingBox:':
                    line[1] = str(float(line[1]) - 1.0)
                    line[2] = str(float(line[2]) - 1.0)
                    line[3] = str(float(line[3]) + 2.0)
                    line[4] = str(float(line[4]) + 2.0)
                line = ' '.join(line)
                o.write(line+'\n')
于 2012-11-26T17:24:24.500 回答