Reputation: 30231
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?
Upvotes: 24
Views: 17774
Reputation: 384404
Tested as of 6.9.11, the default background is now white, not transparent, at least for PNG input/output.
To get a transparent background you need something like:
convert source.png -gravity north -background transparent -splice 0x10 out.png
north
adds on top, south
on bottom.
Also note that -background
has to come before -splice
.
Demo JPG input:
wget -O chick.jpg https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/Hühnerküken_02.jpg/800px-Hühnerküken_02.jpg
Unmodified input preview:
100 px white border on top with -gravity north
(white is the default color):
convert chick.jpg -gravity north -splice 0x100 chick-default.jpg
100 px black border on top with -background black
:
convert chick.jpg -gravity north -background black -splice 0x100 chick-black.jpg
Black border on bottom with -gravity south
:
convert chick.jpg -gravity south -background black -splice 0x100 chick-black-south.jpg
Black border on both top and bottom with a double -gravity
+ -splice
:
convert chick.jpg -background black -gravity south -splice 0x100 \
-gravity north -splice 0x100 chick-black-north-south.jpg
100px black border all around image instead with -border
as per https://askubuntu.com/questions/819482/how-to-add-a-border-using-imagemagick
convert -bordercolor black -border 100 chick.jpg chick-around.jpg
Upvotes: 3
Reputation: 7844
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.
Upvotes: 23
Reputation: 40262
Use -extent
instead:
convert source.jpg -gravity south -extent 100x50 out.jpg
-gravity
tell it which direction to move the original image.
Upvotes: 5