Skip to content

Instantly share code, notes, and snippets.

@TakashiUNUMA
Created July 5, 2014 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TakashiUNUMA/2a3f9213836411133220 to your computer and use it in GitHub Desktop.
Save TakashiUNUMA/2a3f9213836411133220 to your computer and use it in GitHub Desktop.
A shell script for modifying the bounding box of the input eps files using ghostscript.
#!/bin/sh
#
# modify_boundingbox.sh
#
# original script coded by Takashi Unuma, Kyoto Univ.
# last modified: 2014/07/06
#
# required commands: basename, gs, sed, and awk
#
# check arguments
if test $# -lt 1 ; then
echo "USAGE: $(basename $0) [EPS file(s)]"
exit
fi
# execute section
for file in $* ; do
# get a "true" bounding box information in the specified eps file
bbinfo=$(gs -q -dNOPAUSE -dBATCH -sDEVICE=bbox ${file} 2>&1 | sed -e "s/\%/\\\%/g" -e "s/\:/\\\:/g" -e "s/\./\\\./g" -e "s/[[:blank:]]/\\\ /g" | awk '{printf $0}')
# overwrite the information of bounding box
sed -i -e "2c${bbinfo}" -e "3d" ${file}
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment