image-processingimage-manipulationimagemagick-convert

Imagemagick inline border without resizing the original image


I tried to add a border to an image of dimension 200x200 px using the below code.

convert -border 2x2 -bordercolor "#cccccc" old.png new.png

The above code ads a 2 px border around the old.png. Therefore, the image expands to 204x204 px.

However, I want to add an inline border. I have no issues with border overlaying edge portions of the old image. Thus, the new image should be able to retain the dimensions 200x200 px. Please advise how exactly to do that.


Solution

  • You need to shave two pixels all around and then add a two pixel border. You should try this with Imagemagick 6. If using Imagemagick 7, replace convert with magick.

    convert old.png -shave 2x2 -bordercolor "#cccccc" -border 2 new.png