首页 > 技术文章 > 剪切Postscript图片中的多余边框

liyropt 2013-09-11 13:34 原文

最近用plplot画图,其cairo ps库生成的ps图片总是不能合理地剪切掉多余的边框,于是乎自己写了一个小脚本epscrop,用修改ps图的BoundingBox.

#!/bin/bash

# check if the argument is provided.
if [ $# -lt 1 ]
then
  echo "no file specified."
  exit
fi

fname=$1

#check if the file exits.
if [ ! -f $fname ]
then
  echo "file $fname not exists."
  exit
fi

#get the bounding box
box=$(gs -sstderr=%stdout -dQUIET -dBATCH -DNOPAUSE -sDEVICE=bbox $fname 2>&1 | sed -n -e "s/%%BoundingBox:\(.*\)/\1/p")

#change the bounding box
sed -i -e "/%%DocumentMedia:/d" $fname
sed -i -e "s/\(%%BoundingBox:\)\(.*\)/\1$box/" -e "s/\(%%PageBoundingBox:\)\(.*\)/\1$box/" $fname

 用法: ./epscrop psfile,   效果如下,

     

推荐阅读