Create borders from texture images

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
kostya572
Posts: 5
Joined: 2017-06-23T16:23:37-07:00
Authentication code: 1151

Create borders from texture images

Post by kostya572 »

IM Version: ImageMagick 6.8.9-9 Q16 x86_64 2017-05-26
Platform: Linux Shell

To create simple borders with hex codes i can use:
convert image.jpg -bordercolor '#000000' -border '50'

But how can i use texture image (texture.jpg) for border instead of hex color with border size 50?

Input image - http://i.piccy.info/i9/fce981a9a39eb4b5 ... iginal.jpg
Texture image - http://i.piccy.info/i9/1c53c04cd234e838 ... exture.jpg
Desired result - http://i.piccy.info/i9/2e3a0fc62948cb94 ... result.jpg

Thank you
Last edited by kostya572 on 2017-06-23T19:22:29-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create borders from texture images

Post by fmw42 »

Please always provide your IM version and platform, since syntax differs. Also please post your input image and the desired texture image, so we can show you on your own images. You can post your images to some free hosting service and put the URLs here.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at viewtopic.php?f=1&t=9620

For novices, see

viewtopic.php?f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
kostya572
Posts: 5
Joined: 2017-06-23T16:23:37-07:00
Authentication code: 1151

Re: Create borders from texture images

Post by kostya572 »

fmw42 wrote: 2017-06-23T18:56:11-07:00 Please always provide your IM version and platform, since syntax differs. Also please post your input image and the desired texture image, so we can show you on your own images. You can post your images to some free hosting service and put the URLs here.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at viewtopic.php?f=1&t=9620

For novices, see

viewtopic.php?f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
Thank you for explaining the rules, I have updated my question.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create borders from texture images

Post by fmw42 »

try this:

Code: Select all

convert \
\( original.jpg -bordercolor none -border 50 \) \
\( -clone 0 -tile texture.jpg -draw "color 0,0 reset" \) \
+swap -compose over -composite result.jpg
Image

See:
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/basics/#clone
http://www.imagemagick.org/Usage/basics/#swap
http://www.imagemagick.org/Usage/canvas/#tile
kostya572
Posts: 5
Joined: 2017-06-23T16:23:37-07:00
Authentication code: 1151

Re: Create borders from texture images

Post by kostya572 »

fmw42 wrote: 2017-06-23T19:50:01-07:00 try this:

Code: Select all

convert \
\( original.jpg -bordercolor none -border 50 \) \
\( -clone 0 -tile texture.jpg -draw "color 0,0 reset" \) \
+swap -compose over -composite result.jpg
Image

See:
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/basics/#clone
http://www.imagemagick.org/Usage/basics/#swap
http://www.imagemagick.org/Usage/canvas/#tile
Thank you, it works :)
kostya572
Posts: 5
Joined: 2017-06-23T16:23:37-07:00
Authentication code: 1151

Re: Create borders from texture images

Post by kostya572 »

fmw42 wrote: 2017-06-23T19:50:01-07:00 try this:

Code: Select all

convert \
\( original.jpg -bordercolor none -border 50 \) \
\( -clone 0 -tile texture.jpg -draw "color 0,0 reset" \) \
+swap -compose over -composite result.jpg
Image

See:
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/basics/#clone
http://www.imagemagick.org/Usage/basics/#swap
http://www.imagemagick.org/Usage/canvas/#tile
Hi, fmw42

Could you provide me the same solution with oval border?
I've found the solution here - viewtopic.php?t=18126#p69057 but it combines image + texture with exact size

Thank you
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create borders from texture images

Post by fmw42 »

Code: Select all

ww=`convert original.jpg -format "%w" info:`
hh=`convert original.jpg -format "%h" info:`
rx=`convert xc: -format "%[fx:$ww/2]" info:`
ry=`convert xc: -format "%[fx:$hh/2]" info:`
cx=`convert xc: -format "%[fx:$ww/2]" info:`
cy=`convert xc: -format "%[fx:$hh/2]" info:`
echo "$ww $hh $rx $ry"
convert \
\( original.jpg \( -size ${ww}x${hh} xc:black -fill white -draw "translate $cx,$cy ellipse 0,0 $rx,$ry 0,360" \) \
-alpha off -compose copy_opacity -composite \) \
\( -clone 0 -tile texture.jpg -draw "color 0,0 reset" \) \
+swap -compose over -composite result2.jpg
Image
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Create borders from texture images

Post by GeeMack »

kostya572 wrote: 2017-06-27T10:52:03-07:00Could you provide me the same solution with oval border?
I've found the solution here - viewtopic.php?t=18126#p69057 but it combines image + texture with exact size
The solution fmw42 gave above will put an oval frame on your original, keeping the original dimensions. If you want to also add another 50 pixels on each side, you'll need to account for that, too. A command like this works for me using IM 6.7.7-10 from a bash shell prompt...

Code: Select all

IM_VAR=`convert original.jpg -format "%[fx:w/2],%[fx:h/2]" info:`

convert original.jpg -alpha set -bordercolor black \
   \( -clone 0 -fill black -colorize 100 -fill white -draw "ellipse $IM_VAR $IM_VAR 0,360" \) \
   -border 50 \( -tile texture.jpg -clone 0 -draw "color 0,0 reset" \) -insert 0 -composite result.png
kostya572
Posts: 5
Joined: 2017-06-23T16:23:37-07:00
Authentication code: 1151

Re: Create borders from texture images

Post by kostya572 »

Thank you guys, you helped me a lot, everything works perfectly :)
Post Reply