How to expand an image background with Imagemagick

Let’s say you have an image with a following dimensions:

 $ identify logo.jpg 
logo.jpg JPEG 400x178 400x178+0+0 8-bit sRGB 55.6KB 0.000u 0:00.000

and white background as for an example:

extent image background original image

However, what we need is in image with a white background with 400×200 pixels dimensions. What we need to do in this case is to create a new 400×200 white canvas and center place our existing image it it. For this an Imagemagick provides a simple solution:

$ convert logo.jpg -gravity center -background white -extent 400x200 new_logo.jpg
$ identify new_logo.jpg
new_logo.jpg JPEG 400x200 400x200+0+0 8-bit sRGB 57.1KB 0.000u 0:00.000

extent image background white new image

Comments and Discussions
Linux Forum