Skip to content

Instantly share code, notes, and snippets.

@ebouchut
Last active August 29, 2015 14:16
Show Gist options
  • Save ebouchut/830b8a535c3bc8951e28 to your computer and use it in GitHub Desktop.
Save ebouchut/830b8a535c3bc8951e28 to your computer and use it in GitHub Desktop.
Resize and increase the canvas size of an image to 225x100 using imagemagick
# I want to resize an image from 600x128 to 225x100 while keeping its aspect ratio.
# Resizing the width to 225 while keeping the aspect ratio makes one dimension (height)
# smaller (225x48) than what I want to obtain (225x100).
# The workaround is to resize first,
# then increase the canvas of the other dimension (height)
# to obtain the desired size (225x100) then center the image in the canvas.
#~~~~~~~~~~~~~~~~~~~~~
# Step #1: Resize the width first to 225 keeping the aspect ratio (=> 225x48)
# This is not enough.
#~~~~~~~~~~~~~~~~~~~~~
convert image_600x128.png -resize 225 image_225x.png
#~~~~~~~~~~~~~~~~~~~~~
# Step #2: Now increase the canvas size setting height to 100 and center the image
# ~~~~~~~~~~~~~~~
convert image_225x.png -gravity center -extent 225x100 -transparent white image_225x100.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment