Page 1 of 1

Add border to text with texture

Posted: 2016-11-25T06:45:09-07:00
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

Re: Add border to text with texture

Posted: 2016-11-25T07:17:54-07:00
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".

Re: Add border to text with texture

Posted: 2016-11-25T09:05:52-07:00
by tunezio
I tried to add "-background none" before "-extent" but It did not work for me.

Re: Add border to text with texture

Posted: 2016-11-25T10:57:41-07:00
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.

Re: Add border to text with texture

Posted: 2016-11-28T02:11:06-07:00
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

Re: Add border to text with texture

Posted: 2016-11-28T07:06:54-07:00
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.

Re: Add border to text with texture

Posted: 2016-11-28T09:49:57-07:00
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

Re: Add border to text with texture

Posted: 2016-11-28T10:35:49-07:00
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.

Re: Add border to text with texture

Posted: 2016-11-29T03:29:16-07:00
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

Re: Add border to text with texture

Posted: 2016-11-29T10:23:32-07:00
by fmw42
Please supply your font and your texture image.

Re: Add border to text with texture

Posted: 2016-11-30T02:31:23-07:00
by tunezio
Thank you

you can find files in the link below
http://www.filedropper.com/imagemagick

Re: Add border to text with texture

Posted: 2016-11-30T08:28:24-07:00
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.

Re: Add border to text with texture

Posted: 2016-11-30T11:46:37-07:00
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.