Skip to content

Instantly share code, notes, and snippets.

@carlynorama
Last active Aug 29, 2015
Embed
What would you like to do?
Crops an image file to a specified size and offset, renames with same prefix as original. Requires ImageMagick.
#!/bin/bash
#Crops an image file to a specified size and offset,
#renames with same prefix as original.
#REQUIRES ImageMagick.
Y1=$1
Y2=$2
X1=$3
X2=$4
MYDIR="corner_keys"
EXT="png"
if [[ -z $Y1 ]]; then Y1=88 ; fi
if [[ -z $Y2 ]]; then Y2=212 ; fi
if [[ -z $X1 ]]; then X1=193 ; fi
if [[ -z $X2 ]]; then X2=497 ; fi
let KEYWIDTH=$X2-$X1
let KEYHEIGHT=$Y2-$Y1
PREFIXLENGTH=6
if [ ! -d ./${MYDIR} ]; then mkdir ./${MYDIR}; fi
# processes all pngs
if ls | grep png; then for p in *.png; do
echo "Processing $p"
prefixonly=${p:0:$PREFIXLENGTH}
convert \( $p -crop ${KEYWIDTH}x${KEYHEIGHT}+${X1}+${Y1} +repage \) \
./${MYDIR}/${prefixonly}_cnrkey.png
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment