Add border to text with texture

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
tunezio
Posts: 26
Joined: 2016-08-09T08:59:20-07:00
Authentication code: 1151

Add border to text with texture

Post by tunezio »

Hello
I use convert to generate an image using the command below. It works for me, but when i want to add a barder, i obtain a bad result.
I explain my code, I generate a transparent (png) image contains a text with background texture (for the text).
I want to add a border to the text and I get a bad result

Code: Select all

convert 
-background none 
-fill white 
-gravity center 
-pointsize 96 -size x134 
-font "lobster1.4.ttf" 
label:"My text" 
\( -clone 0 -tile texture_C3F000.jpg -draw "color 0,0 reset" -fill "#C3F000" -colorize 50% \)
 \( -clone 0 -fill "none" -colorize 100% \) 
 -reverse -compose over -composite -alpha set -virtual-pixel transparent -channel A -blur 0x0.7 -level 50,100% +channel 
 -resize "240x114>" -extent 240x114 
 \( +clone -background black -shadow 80x3+0+0 \) +swap -background none -layers merge +repage 
 338b02ce4ce95ecb6d4aa5631e.png
Image

Thanks
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Add border to text with texture

Post by snibgo »

See http://www.imagemagick.org/script/comma ... php#extent :
If the image is enlarged, unfilled areas are set to the background color.
You have a background colour. Try "-background none" before "-extent".
snibgo's IM pages: im.snibgo.com
tunezio
Posts: 26
Joined: 2016-08-09T08:59:20-07:00
Authentication code: 1151

Re: Add border to text with texture

Post by tunezio »

I tried to add "-background none" before "-extent" but It did not work for me.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Add border to text with texture

Post by fmw42 »

Create your green text image. Then create a larger background image that your green texture. Then overlay your text image onto the background green image in the center of the background image.
tunezio
Posts: 26
Joined: 2016-08-09T08:59:20-07:00
Authentication code: 1151

Re: Add border to text with texture

Post by tunezio »

Thank you for the answer, i tried your solution and i don't get a good result.
The text still have background.

Image
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Add border to text with texture

Post by GeeMack »

tunezio wrote:Thank you for the answer, i tried your solution and i don't get a good result.
The text still have background.
Nobody can help you fix your command if you don't post the command for us to see.
tunezio
Posts: 26
Joined: 2016-08-09T08:59:20-07:00
Authentication code: 1151

Re: Add border to text with texture

Post by tunezio »

Thank you for your answer.
I finaly fix this problem and get a good rsult, but i still have a problem. The text remains glued to the border using different fonts. who can help me to solve this problem
My command is :

Code: Select all

convert -background none -fill white -gravity center -pointsize 96 -size x114 -font "lobster1.4.ttf" label:"My\ test" -compose Copy -border 8x8 \( -clone 0 -tile texture_C3F000.jpg -draw "color 0,0 reset" -fill "#C3F000" -colorize 50% \) \( -clone 0 -fill "none" -colorize 100% \) -reverse -compose over -composite -alpha set -virtual-pixel transparent -channel A -blur 0x0.7 -level 50,100% +channel -resize "240x114>" -extent 240x114 \( +clone -background black -shadow 80x3+0+0 \) +swap -background none -layers merge +repage 75f0f60eb.png
Image
Image
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Add border to text with texture

Post by fmw42 »

Make your background green image bigger and pad your text image before compositing by adding -bordercolor white or none (as appropriate) and -border X where X will be the pad amount.
tunezio
Posts: 26
Joined: 2016-08-09T08:59:20-07:00
Authentication code: 1151

Re: Add border to text with texture

Post by tunezio »

Thank you for your answer
But i don't understand what do you mean. I genereate my image with text without background green image. i add a border on the same time as the text.
You can edit my command with your proposition and explain please.

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

Re: Add border to text with texture

Post by fmw42 »

Please supply your font and your texture image.
tunezio
Posts: 26
Joined: 2016-08-09T08:59:20-07:00
Authentication code: 1151

Re: Add border to text with texture

Post by tunezio »

Thank you

you can find files in the link below
http://www.filedropper.com/imagemagick
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Add border to text with texture

Post by GeeMack »

tunezio wrote:The text remains glued to the border using different fonts. who can help me to solve this problem
Most fonts are designed with some amount of space above and below the character, but each font will be different from another. For example, your "spiderman.ttf" leaves almost no whitespace above the text and a lot of space below it. That's up to the designer of the font. It's not really an ImageMagick thing. You'll have to deal with each font differently and/or write your commands to handle those variables.

If you want to make sure there's some space around your text, do what fmw42 suggested and add a transparent or white border to your text block right after you create it. Maybe even try "-trim" to remove the uneven space surrounding the text block, then add the borders to make the same amount of padding all around.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Add border to text with texture

Post by fmw42 »

You provided the wrong font for your example and that code does not work for me. It only fills in the first letter with green. Nevertheless, if you want spaces, try

Code: Select all

convert -background none -fill white -gravity center -pointsize 96 \
	-size x114 -font "/library/fonts/spiderman.ttf" label:"My\ test" \
-trim +repage -bordercolor none -border 8x8 -bordercolor white -border 8x8  \
\( -clone 0 -tile texture_C3F000.jpg -draw "color 0,0 reset" -fill "#C3F000" -colorize 50% \) \
\( -clone 0 -fill "none" -colorize 100% \) \
-reverse -compose over -composite \
-alpha set -virtual-pixel transparent -channel A -blur 0x0.7 -level 50,100% +channel \
-resize "240x114>" -extent 240x114 \( +clone -background black -shadow 80x3+0+0 \) \
+swap -background none -layers merge +repage 75f0f60eb.png
The new code is the third line and replaces simply your -border 8x8. If you want more space, then increase the first -border size after the -trim

Also it is easier to read, though I did not follow your code at all, if you break into logical sections using \ at the end of the line and a line feed afterwards.
Post Reply