views:

389

answers:

2

I have an image 100x40 and I want to add a border to the top of the image 10 pixels high.

I've found

convert source.jpg -border 0x10 out.jpg

but this adds a border to the top and bottom. Is there anyway to add it to only the top?

A: 

Use -extent instead:

convert source.jpg -gravity south -extent 100x50 out.jpg

-gravity tell it which direction to move the original image.

eduffy
I should have said, I'm doing this to a batch of images which all have different sizes so I wouldn't be able to know what dimensions to pass to the -extent option. Having said that, it's a very useful option to know about.
opsb
+2  A: 

Use -splice:

convert source.jpg -splice 0x10 out.jpg

If you want to add the border only at the bottom, use -gravity as well: convert source.jpg -gravity south -splice 0x10 out.jpg

Note that the border will be transparent, unless you use -background, too.

See also Cutting and Bordering for more examples.

Danilo Piazzalunga