Skip to content

Instantly share code, notes, and snippets.

@Rudis1261
Created March 25, 2015 06:57
Show Gist options
  • Save Rudis1261/ac876de36652d6961ecf to your computer and use it in GitHub Desktop.
Save Rudis1261/ac876de36652d6961ecf to your computer and use it in GitHub Desktop.
Center Cropping images with ImageMagick
echo "Creating thumbnail of ${1}, to ${2}"
echo "Dimensions: ${3}px X ${4}px"
convert $1 -format png -strip -resize $3'x'$4'^' -gravity center -crop $3x$4'+0+0' $2
@Rudis1261
Copy link
Author

Getting it

wget -O center_crop.sh http://git.io/jTIC
chmod +x center_crop.sh

Usage

./center_crop.sh <input_file_name> <output_file_name> <width> <height>

Examples

./center_crop.sh input_file.png output_file.png 180 265

Will create a cropped image with the dimensions of 180px wide by 265px high.

./center_crop.sh input.png input_thumb.png 150 150

Will create a cropped square image with the dimensions of 150px wide by 150px high.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment