Page 1 of 1
Put a Text with transparent Background into a Image
Posted: 2011-03-12T09:49:20-07:00
by GTRDRIVER
Hello
I just wat to put some "TEXT-Messages" into several Pictures with a transparent Background - but i dont know how...
For usual Background at TEXT i use: -undercolor COLOR
So i get a text within the Picture and the Text "sit" in a Colored Box within the Picture - so fare so good...
But i want to have a Transparency Box in wich i have the TEXT-Message.
Because is use this in a automated Script with different TEXT Font´s and different Font Sizes i cannot "DRAW" the BOX manualy.
So how can i use -undercolor to do it Transparency - the best solution would be to if i can set the level of Transparency in Percent (1-100%)
Perhaps - anyone of you can help me
Sorry for poor English...
Best Regards.
GTR
Re: Put a Text with transparent Background into a Image
Posted: 2011-03-12T12:13:36-07:00
by fmw42
IM will not generally insert transparency as an undercolor, as far as I know.
I think what you have to do is:
1) Draw a block of color where you want to put your transparency. Some color that is not in your image at that spot.
2) Draw matte floodfill to fill that color with transparency
3) Draw or Annotate your text within that transparent area
see drawing a colored rectangle at
http://www.imagemagick.org/Usage/draw/#primitives
see matte floodfill at
http://www.imagemagick.org/Usage/draw/#matte
see putting text in your image with draw or annotate at
http://www.imagemagick.org/Usage/text/#draw
http://www.imagemagick.org/Usage/text/#annotate
Re: Put a Text with transparent Background into a Image
Posted: 2011-03-12T15:01:04-07:00
by GTRDRIVER
Hi
Thanks for your Answer
Because i use IM within a bigger Software wich should give some options to the user:
- Position of the Text
- Font-Size of the Text
- Text-Lenth
- Font Style
Im not able to calculate where the TEXT will be displayed on the Image and how log it is... - so im not able to draw the "Transparent" Box to the right position and with the right dimentions.
Perhaps i´m wrong ?
CU
Re: Put a Text with transparent Background into a Image
Posted: 2011-03-12T19:40:09-07:00
by anthony
You will need to set the undercolor as a semi-transparent color. Unfortunatally you can not currently specify a named color with a transparency value. If you want this, put in a suggestion in the Developers forum. I have been wanting that is for years myself!
See IM Examples, Color Specification
http://www.imagemagick.org/Usage/color_basics/#color
and the Offical Page, Color Names
http://www.imagemagick.org/script/color.php
For ways of annotating images using an surrounding 'undercolor' or 'dimmed box' see IM examples, Annotations
Labeling on top of the Image itself..
http://www.imagemagick.org/Usage/annotating/#anno_on
Re: Put a Text with transparent Background into a Image
Posted: 2011-03-13T11:12:29-07:00
by fmw42
Anthony,
Are you saying if you specify the undercolor as "rgba(0,0,0,0)" one would have a completely transparent undercolor "forced" into an opaque image when annotating text?
Fred
Re: Put a Text with transparent Background into a Image
Posted: 2011-03-13T18:40:56-07:00
by anthony
Well I wouldn't say 'forced'. But it will be drawn. But as you know drawing transparency does nothing!
Try using rgba(0,0,0,0.5) to see undercolor effects.
Re: Put a Text with transparent Background into a Image
Posted: 2011-03-13T18:43:33-07:00
by fmw42
Anthony,
If I understand correctly, the originator of this topic is trying to write text to an opaque image where the undercolor is transparent in the sense that it makes the image transparent where the undercolor exists (i.e. a hole). Is this possible without something like the steps that I listed above?
Fred
Re: Put a Text with transparent Background into a Image
Posted: 2011-03-13T19:06:33-07:00
by anthony
Only by generating a separate image (such as a label), and using -compose copy to overlay it!
http://www.imagemagick.org/Usage/compose/#copy
Or erasing the original image to make the hole first.
Re: Put a Text with transparent Background into a Image
Posted: 2011-03-14T16:51:24-07:00
by fmw42
Yes, this seems to work:
convert logo: \( -size 100x -font /Library/fonts/arial.ttf -pointsize 24 -background none -fill black -gravity center label:"testing" \) -channel rgba -alpha set -gravity center -compose copy -composite tmp.png