borders on the inside

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
xms

borders on the inside

Post by xms »

Hi guys and gals,

When i add borders to images, it places the border on the outside of the image thus increasing the images dimensions.

How can i add a border to the inside of the image, so that the image retains its previous dimensions but has a border overlayed around the edges of the image?

Cheers :)
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Draw, a rectangle with the right stroke width around your image.

Hmmm a rose is 70x46 pixels, so...

Code: Select all

   convert rose: -fill none -stroke navy -strokewidth 11  \
           -draw 'rectangle 0,0 69,45'   inside_border.jpg
the stroke width = {border width wanted} * 2 -1

EG: 1 -> stroke width of 1
6 -> stroke width of 11 (as above)

:P

I have no idea where this should be put in IM Examples!!!!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
xms

Post by xms »

Thanks for that anthony - but what about if you don't know the size of the image?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Then you will have you use -chop and -slice.. on the edges with gravity settings
Once on diagonally oppist corners will do the trick.

Code: Select all

convert rose: -background green -chop 6x6+0+0 -splice 6x6+0+0  \
                      -gravity SouthEast -chop 6x6+0+0 -splice 6x6+0+0 \
                     +gravity          inside_border_spliced.jpg
Addes to IM Examples misc -- will appear in a few hours there
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
xms

Post by xms »

You're a diamond :)

I do have one more question however (sorry). I'll post a new thread for it.
Post Reply