Use ImageMagick to place an image inside a larger canvas

Getting started with ImageMagic and trying to find a way to do this ... If the image is less than 50 pixels high or 50 pixels wide, I would like to place it (without scaling) in the horizontal / vertical center of a new canvas measuring 50x50 pixels on a white background - and save it as a new image. Does anyone know if this is possible with ImageMagick? Thank!

+45
imagemagick
Nov 24 '09 at 2:10
source share
7 answers

I used -extent for this:

convert input.jpg -gravity center -background white -extent 50x50 output.jpg 
+91
Sep 23 '10 at 19:34
source share
— -

See cutting and settling for a wide variety of examples. Here is an easy way to do this:

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

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

+3
Nov 24 '09 at 2:25
source share

I tried this:

 convert test.jpg -resize 100x100 -background black -gravity center -extent 100x100 output.png 
+2
May 02 '10 at 22:12
source share

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

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

Not quite what was requested, but hopefully this helps someone;).

+2
Nov 17 '14 at 11:07
source share

You can use a single composition for this. Therefore, it looks something like this:

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

+1
Feb 01 '10 at 9:48
source share

To change the original image, you need to use mogrify:

 mogrify -gravity center -background white -extent 50x50 source.jpg 
+1
Apr 6 '13 at 7:18
source share

I used this code to place the image in the center of a new canvas with a white background. hope this helps you

 convert -background white -gravity center your_image.jpg -extent 50x50 new_image.jpg 
+1
Jun 14 '16 at 6:39
source share



All Articles