#!/bin/bash # Address questions to matt silver echo ''; # get the name of the input and output files INFILE=${1%}; OUTFILE=${2%}; ######################################################## # find the BoundingBox line BBOX=`grep %%BoundingBox: $INFILE`; echo 'Found bounding box: ' $BBOX; ######################################################## # tokenize the bounding box string ARR=(${BBOX}); # the bad one is always the first one, I think... BADBOUND=${ARR[1]}; echo 'Found the offending boundary: ' $BADBOUND; # replace the undesired boundary with 0 BBOXNEW=${BBOX/$BADBOUND/0}; # find the bound that must now be adjusted ADJBOUND=${ARR[3]}; # determine the value that this bound should have NEWBOUND=$(($ADJBOUND - $BADBOUND)); # replace the adjusted bound with the new value BBOXNEW=${BBOXNEW/$ADJBOUND/$NEWBOUND}; echo 'Correct bounding box: ' $BBOXNEW; ######################################################## # generate additional line to translate image TRANSLATE=`echo ${BADBOUND:1} '0 translate'`; echo 'Translating by adding: ' $TRANSLATE; echo ''; ####################################################### # copy the contents of INFILE into OUTFILE `cp $INFILE $OUTFILE`; # replace the old bounding box line with the new one sed -i "s/$BBOX/$BBOXNEW/" $OUTFILE; # translate the image sed -i "s/%%EndComments/%%EndComments\n\n$TRANSLATE/" $OUTFILE; echo 'Done!!';