#!/bin/bash
FILE=$1
RESOLUTION=`identify "$1" | sed 's/^.*\ \(\w*\)x\(\w*\)\ .*$/\1\ \2/'`
set $RESOLUTION
HORIZ=$1
VERT=$2
ROTATE=NOROTATEif [ $HORIZ -le $VERT ]
then
ROTATE=ROTATE
TEMP=$VERT
VERT=$HORIZ
HORIZ=$TEMP
fi
echo "Size: $HORIZ x $VERT $ROTATE"
let TEMP1=$HORIZ*2
let TEMP2=$VERT*3
rotatecmd=""
if [ $TEMP1 -le $TEMP2 ]
then
let TEMP=$TEMP2-$TEMP1
let NEWVERT=$VERT-$TEMP/3
NEWHORIZ=$HORIZ
let TRIM=$TEMP/6
shavegeometry="0x${TRIM}"
if [ $ROTATE == "ROTATE" ]
then
TEMP=$NEWVERT
NEWVERT=$NEWHORIZ
NEWHORIZ=$TEMP
rotatecmd="-transpose"
shavegeometry="${TRIM}x0"
fi
else
let TEMP=$TEMP1-$TEMP2
let NEWHORIZ=$HORIZ-$TEMP/2
NEWVERT=$VERT
let TRIM=$TEMP/4
shavegeometry="${TRIM}x0"
if [ $ROTATE == "ROTATE" ]
then
TEMP=$NEWVERT
NEWVERT=$NEWHORIZ
NEWHORIZ=$TEMP
rotatecmd="-transpose"
shavegeometry="0x${TRIM}"
fi
fi
echo "New size: $NEWHORIZ x $NEWVERT $ROTATE"
TMPFILE=/tmp/`basename "$FILE"`
convert "$FILE" -shave $shavegeometry $rotatecmd "$TMPFILE"
lp -o media=matte -o PageSize=4X6.bl -o fitplot "$TMPFILE"
rm "$TMPFILE"