Inner border

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Inner border

Post by josephs »

Hi.

Is there a quick way to add an inner border to an image? I have been using -border, but as expected it adds the border outside of the image creating a larger image.

Any help is appreciated.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Inner border

Post by snibgo »

You can shave pixels from the edges before adding the border. See http://www.imagemagick.org/script/comma ... .php#shave
snibgo's IM pages: im.snibgo.com
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Re: Inner border

Post by josephs »

Just what I was looking for. Thank you!
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Inner border

Post by GeeMack »

josephs wrote: 2017-04-20T07:15:19-07:00Is there a quick way to add an inner border to an image? I have been using -border, but as expected it adds the border outside of the image creating a larger image.
Yep, as snibgo mentioned, you can shave off a given amount of the image, then add a border of that same amount. In its simplest form, to get an inner border of 6 pixels for example, you could put something like this into your command...

Code: Select all

... -shave 6 -border 6 ...
Of course you can make the horizontal borders different widths than the vertical borders with "-shave WxH -border WxH". You can also work all those borders separately by applying "-chop" and "-splice" operations. It's just about the same, but you'll have to make sure your gravity settings are correct for each operation.
josephs
Posts: 40
Joined: 2014-04-08T10:13:43-07:00
Authentication code: 6789

Re: Inner border

Post by josephs »

Yup nice and simple. Works.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Inner border

Post by snibgo »

It is simple, and quick to write. It probably isn't the quickest to execute. It may be quicker to draw four rectangles of the required size, one per edge, especially if the image is large but the border is thin.
snibgo's IM pages: im.snibgo.com
Post Reply