Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add inner border with some padding to an image using imagemagick?

I am using imagemagick to add a border to an image.

I can add the border with the following code:

convert source.jpg -shave 10x10 -bordercolor red -border 2 final.jpg

The code above generates this image:

enter image description here

However, what i need to generate is something like this:

enter image description here

If you look at the red border in the second image, you would see the difference between that image and the first image which i currently create using imagemagick.

Could someone please advise on this?

Thanks in advance.

like image 586
David Hope Avatar asked Dec 23 '22 15:12

David Hope


1 Answers

You do not say what version you are using or what code laungage either.

convert wizard: -stroke red -strokewidth 2 -fill transparent -draw "roundrectangle 10,10 470,627 10,10" output.png

If using version 7 you can calculate the dimensions within the command otherwise you need to get the dimensions of the image, do the calculations and input them into the command with a variable.

like image 106
Bonzo Avatar answered Jan 31 '23 01:01

Bonzo