Skip to content

Instantly share code, notes, and snippets.

@wpyoga
Created May 25, 2021 07:17
Show Gist options
  • Save wpyoga/b984279eb717d0143e252d23adcfe535 to your computer and use it in GitHub Desktop.
Save wpyoga/b984279eb717d0143e252d23adcfe535 to your computer and use it in GitHub Desktop.
ImageMagick crop then resize image
# -crop 2250x1518+0+0
# crop the image to 2250x1518
# without this, the image will be resized to
# - 800x541, if using the geometry transform
# - 799x540, if using the resize transform
#
# +repage
# reset the virtual canvas to the image size, which has been cropped
#
# -geometry 800
# resize the image so that it has a width of 800 pixels
#
# -resize 800x540
# resize the image so that it fits a box with 800 pixels in width and 540 pixels in height
# see the note on -crop above for more details
#
convert image.png -crop 2250x1518+0+0 +repage -geometry 800 resized.png
convert image.png -crop 2250x1518+0+0 +repage -resize 800x540 resized.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment