Page 2 of 2
Re: Putting text in a rectangle or an overalyed image
Posted: 2017-04-18T04:47:53-07:00
by Bonzo
Try caption:
What you want and what you can have are not always the same thing; sometimes you need to compromise.
I do not think fmw42's examples are using C and you may have more problems if the C API when you decide to use it does not support what you want to do. In that case you may need to decide on a different programming method
You can create a separate image with the text in and add it to the bottom of the image which means you can control everything but it will be another step.
Re: Putting text in a rectangle or an overalyed image
Posted: 2017-04-18T09:27:20-07:00
by fmw42
him21sri wrote: ↑2017-04-18T03:55:17-07:00
By my understanding annotate will just put text on an image of a defined size but I want the background with some transparency as well, if I set background it will set for the whole image which I don't want. I just want to have a small rectangle at the bottom of image with some color and transparency with some center aligned text.
Set the background color with an alpha value, such as rgba(255,255,0,0.5) as half transparent yellow or use hex notation. See
http://www.imagemagick.org/script/color.php
If you do not want the text to stretch, then specify -size WxH and pointsize in the label: command
For example, for half transparent yellow:
Code: Select all
wid=`convert logo2.gif -format "%w" info:`
convert logo2.gif A_image2.gif -gravity northeast -compose over -composite \
\( -size ${wid}x50 -background "rgba(255,255,0,0.5)" -font arial -pointsize 18 \
-fill black -gravity center label:"This Is Some Text" \) \
-append result.png
For fully transparent background use color "none" or "transparent"
Code: Select all
wid=`convert logo2.gif -format "%w" info:`
convert logo2.gif A_image2.gif -gravity northeast -compose over -composite \
\( -size ${wid}x50 -background none -font arial -pointsize 18 \
-fill black -gravity center label:"This Is Some Text" \) \
-append result.png
If you do not want to use rgb or hex color, but have transparent named colors, then you can do it this way:
Code: Select all
wid=`convert logo2.gif -format "%w" info:`
convert logo2.gif A_image2.gif -gravity northeast -compose over -composite \
\( -size ${wid}x50 xc:yellow -channel a -evaluate set 50% +channel -font arial -pointsize 18 \
-fill black -gravity center -annotate +0+0 "This Is Some Text" \) \
-append result.png
Re: Putting text in a rectangle or an overalyed image
Posted: 2017-04-19T00:15:00-07:00
by him21sri
Thanks guys, I am able to achieve what I wanted from command line. I want to implement this in C I have figured everything out regarding how to implement this except I am not able to use compose method in C when I want to overlay a image on an background image, I am using
https://www.imagemagick.org/api/magick- ... ositeImage method but when I compile the code I get "undefined symbol : MagickCompositeImage". Please suggest what method should I use to overlay an image over an image.
Re: Putting text in a rectangle or an overalyed image
Posted: 2017-04-19T01:35:13-07:00
by snibgo
I asked you:
snibgo wrote:What version of IM? Which C API, MagickCore or MagickWand?
You refer to Wand documentation, so that answers that. But you haven't said which version of IM.
MagickCompositeImage() works fine for me, in v6. Perhaps you are missing a "#include".