tags:

views:

264

answers:

4

Getting started with ImageMagic and trying to find a way to do this... If an image is less than 50 pixels tall or 50 pixels wide, I'd like to place it (un-scaled) in the horizontal/vertical center of a new 50x50 pixel canvas on top of a white background - and save that as the new image. Anyone know if this is possible with ImageMagick? Thanks!

A: 

See cutting and bordering for a huge number of examples. Here's one simple way you might do it:

convert input.png -bordercolor Black -border 5x5 output.png

Of course, you'll need to calculate the size of the border to add (if any) based on the dimensions of the input image. Are you using an ImageMagick API, or just the command line tools?

Adam Rosenfield
A: 

You can use single composition to do this. So it would look something like this:

convert -size 50x50 xc:white null: ( my_image.png -coalesce ) -gravity Center -layers Composite -layers Optimize output.png

Douglas Sellers
+1  A: 

convert test.jpg -resize 100x100 -background black -gravity center -extent 100x100 output.png

Josh
+1  A: 

I used -extent to do this:

convert input.jpg -extent 50x50 -gravity center -background white output.jpg
Jared