Skip to content

Instantly share code, notes, and snippets.

@carlynorama
Last active August 29, 2015 14:12
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 carlynorama/a4ba584b06fb377afc40 to your computer and use it in GitHub Desktop.
Save carlynorama/a4ba584b06fb377afc40 to your computer and use it in GitHub Desktop.
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