Skip to content

Instantly share code, notes, and snippets.

@ooharak
Created September 6, 2014 10:50
Show Gist options
  • Save ooharak/214cfc1b36f73befcdbb to your computer and use it in GitHub Desktop.
Save ooharak/214cfc1b36f73befcdbb to your computer and use it in GitHub Desktop.
EPS: Calculate bounding box and fit
#!/bin/sh
if [ $# -ne 1 ]; then
echo Usage: $0 eps \> svg
exit 1
fi
SRCFILE=$1
BBOXFILE=$(mktemp tmp.XXXXXX)
trap "rm -f $BBOXFILE" EXIT
gs -dNOPAUSE -dBATCH -q -sDEVICE=bbox $SRCFILE > $BBOXFILE 2>&1
sed -f /dev/stdin $SRCFILE <<EOS
/^%%[HiRes]*BoundingBox:.*atend/{;p;d;}
s/^%%BoundingBox:.*$/`grep '^%%BoundingBox:' $BBOXFILE`/g
s/^%%HiResBoundingBox:.*$/`grep '^%%HiResBoundingBox:' $BBOXFILE`/g
EOS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment