Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use ImageMagick to place an image inside a larger canvas

Tags:

imagemagick

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!

like image 456
Mike Avatar asked Nov 24 '09 02:11

Mike


People also ask

How do I resize an image in ImageMagick?

To resize an image to specific dimensions, use the convert command with an input file, the -resize parameter, your preferred dimensions, and an output filename: convert original. png -resize 100x100 new.

What is XC in ImageMagick?

Yes it is purely an alias for xc: which stood for "X window color", which came from the extreme early days of ImageMagick (long before my time).

What can you do with ImageMagick?

ImageMagick can resize, flip, mirror, rotate, distort, shear and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses and Bézier curves.


2 Answers

I used -extent to do this:

convert input.jpg -gravity center -background white -extent 50x50  output.jpg 
like image 127
Jared Avatar answered Sep 22 '22 20:09

Jared


I wanted to do the same, except shrink the image to 70% inside. I used this:

convert input.png -resize 70%x70% -gravity center -background transparent -extent 72x72 output.png 

Not exactly what was requested but hopefully it will help someone ;).

like image 45
gleenn Avatar answered Sep 24 '22 20:09

gleenn