Skip to content

Instantly share code, notes, and snippets.

@chluehr
Created July 22, 2010 13:05
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 chluehr/485932 to your computer and use it in GitHub Desktop.
Save chluehr/485932 to your computer and use it in GitHub Desktop.
BASH: resize/crop via ImageMagick
# BASH: resize/crop via ImageMagick
#==================================
function resizecrop {
SIZE=$1
SRC=$2
DST_PATH=$3
SRC_NAME=`basename $SRC`
# IM 6.3.8+ ONLY! (correct crop center)
#convert -size 300x300 $SRC \
# -thumbnail ${SIZE}x${SIZE}^ \
# -gravity center \
# -extent ${SIZE}x${SIZE} \
# $DST_PATH/$SRC_NAME
# old IM: pad with white ...
convert $SRC \
-resize ${SIZE}x${SIZE}\> \
-size ${SIZE}x${SIZE} xc:white +swap \
-gravity center -composite \
$DST_PATH/$SRC_NAME
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment