【问题标题】:Creating a one-pixel border of whitespace in EPS在 EPS 中创建一个像素的空白边框
【发布时间】:2025-12-07 06:35:02
【问题描述】:

我正在尝试生成一个 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 这样的实用程序的一个选项会很好,这正是我想要的。

【问题讨论】:

  • 对不起,问题不完整,我在完成之前不小心发布了它。我已经对其进行了编辑以包含整个问题陈述。
  • 对我来说似乎是个好问题......

标签: bash latex gnuplot eps


【解决方案1】:

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

awk很容易做到:

awk '/^%%(HiRes)?BoundingBox:/{print $1, $2-1, $3-1, $4+2, $5+2;next}{print}'

【讨论】:

    【解决方案2】:

    我最终编写了一个 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')
    

    【讨论】: