Putting text in a rectangle or an overalyed image

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?".
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Putting text in a rectangle or an overalyed image

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Putting text in a rectangle or an overalyed image

Post 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
him21sri
Posts: 36
Joined: 2016-05-19T05:27:37-07:00
Authentication code: 1151

Re: Putting text in a rectangle or an overalyed image

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Putting text in a rectangle or an overalyed image

Post 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".
snibgo's IM pages: im.snibgo.com
Post Reply