Border Pattern

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
dognose
Posts: 265
Joined: 2005-03-08T22:16:37-07:00

Border Pattern

Post by dognose »

I'm trying to paste an image a number of times around the image.
like so:
Image

I don't want to composite the image 20 times and calculate each position of each overlay

Is there a simpler way to draw a repeating pattern?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Border Pattern

Post by snibgo »

The obvious approach is with tiles. Create a horizontally tiled image for the top and bottom, etc. See http://www.imagemagick.org/Usage/canvas/#tile
snibgo's IM pages: im.snibgo.com
dognose
Posts: 265
Joined: 2005-03-08T22:16:37-07:00

Re: Border Pattern

Post by dognose »

I guess that will work, the stacking isn't going to work right though for a clean border.
the example border is really bad Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Border Pattern

Post by fmw42 »

Create the overlay image by tiling to the nearest integer multiply of the tile size. Mask out the inside so that the tiles are only the at the border. Then resize it to exactly fit your image. Perhaps make your tiles to have a little space around them so that it is easy to mask the inside without cutting into the tiled border.
Last edited by fmw42 on 2013-03-25T10:00:27-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Border Pattern

Post by snibgo »

Whatever method you use, the cleanest result will be when the horizontal repetition is an exact divisor of the image width, so you don't get a broken element. Likewise vertically. You might do this by padding each element. Ideally, the element has binary transparency -- either on or off. Then two elements can be placed at each corner without a problem. I would guess that partial transparency that was only for anti-aliasing would be hardly noticable when doubled-up.

If the image height or width is a prime number, there aren't any divisors, and the best placement might need SRT in a farily messy script.

EDIT: better still, as fmw says, resize the result, provided you don't mind the elements changing their aspect ratios, ie getting "squished".
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Border Pattern

Post by anthony »

dognose wrote:I guess that will work, the stacking isn't going to work right though for a clean border.
the example border is really bad Image
This example was NOT for the border... It was for the offset of the background tiling image!

What you probably want is in Thumbnails, Framing, using edge images...
http://www.imagemagick.org/Usage/thumbnails/#frame_edge

Of course you are not wanting to add an edge, but overlay a tiled edge around the image.

Hmmm...
generate a tiled image the same size... mask it using a shaved/framed mask, then overlay on original image.
You most likely will need to know the size of the image and the tile image.

If the tile images do not tile exactly to match the destination image size, you may like to tile them to fit a image that most closly matches the distination size, then resize the overlay, after masking to fit the destination image. Note the overlay tiles be resized larger or smaller, which ever more closely matches.

Would help if we had links to original images to work with! Especially one that did not 'fit' properly.

Tiling a 'fleur' pattern may be a better final example as it also has 'corners' and different edge tiles for different edges.

I feel a new IM Example coming on, if I can get suitable 'tiles'.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply