Last active
August 29, 2015 14:12
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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