Page 1 of 2
Putting text in a rectangle or an overalyed image
Posted: 2017-04-17T02:34:16-07:00
by him21sri
There are two things which I wanna do -
1. So I have an image, I want to draw a rectangle over it with some opacity and put some text in the center of that rectangle
2. Overlay a small image on the original image and then write some text in the center of that overlayed image.
Text will be a dynamic attribute so it can be long or short.
I want to use C api to do this. Please suggest.
Re: Putting text in a rectangle or an overalyed image
Posted: 2017-04-17T08:05:25-07:00
by snibgo
What version of IM? Which C API, MagickCore or MagickWand?
I suggest you prototype at the command level first. Find the command that does what you want. Then, for each operation and setting, find the C function or data structure.
Re: Putting text in a rectangle or an overalyed image
Posted: 2017-04-17T21:07:09-07:00
by him21sri
I have ImageMagick 6.8.9-10 version.
Please help in prototyping at command level I am not sure how I am gonna place the text in the center of rectangle or an overlayed image, I can find the corresponding C function later.
Re: Putting text in a rectangle or an overalyed image
Posted: 2017-04-17T21:26:17-07:00
by fmw42
You did not say what platform you are using! Please always provide your IM version and platform. Syntax is different for windows and unix. There are many ways to do this. This is only one. It uses the internal IM image logo:. Replace logo: with your image.suffix.
Unix
Code: Select all
convert logo: \( -background none -fill red -font arial -pointsize 48 label:"This Is Text" -bordercolor green1 -border 5 \) -gravity center -compose over -composite logo_text_rectangle.jpg
Windows
Code: Select all
convert logo: ( -background none -fill red -font arial -pointsize 48 label:"This Is Text" -bordercolor green1 -border 5 ) -gravity center -compose over -composite logo_text_rectangle.jpg
see
http://www.imagemagick.org/Usage/text/
http://www.imagemagick.org/Usage/draw/#primitives
http://www.imagemagick.org/Usage/windows/
For novices, see
viewtopic.php?f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
Re: Putting text in a rectangle or an overalyed image
Posted: 2017-04-17T22:42:16-07:00
by him21sri
Sorry for not mentioning the platform I am using, I am doing all this on linux. I want the rectangle to cover the whole width of image and text should be placed in center. I also want to overlay a bookmark type small image on top right of my image and display some text in the center of that overlayed image as present in the sample. Sample :
http://cdn.atomex.net/sample.png
Re: Putting text in a rectangle or an overalyed image
Posted: 2017-04-17T22:55:54-07:00
by fmw42
This forum does not host image. But you can post to any free hosting service and put the URL here. This other post my be of some help.
viewtopic.php?f=1&t=31762.
What is a bookmark type small image?
Re: Putting text in a rectangle or an overalyed image
Posted: 2017-04-17T22:58:43-07:00
by him21sri
I was able to host this image and have shared the same in my old comment, here I am attaching again
http://cdn.atomex.net/sample.png. In this sample image look at the top right corner there is a small black image on which discount is displayed. So I want to overlay that image on my original image and place some text on it
Re: Putting text in a rectangle or an overalyed image
Posted: 2017-04-18T00:32:05-07:00
by fmw42
Here is a simple example:
Input:
Code: Select all
wid=`convert logo2.gif -format "%w" info:`
convert logo2.gif A_image2.gif -gravity northeast -compose over -composite \
\( -size ${wid}x -background black -fill white -gravity center label:"This Is Some Text" \) \
-append result.png
Re: Putting text in a rectangle or an overalyed image
Posted: 2017-04-18T02:55:57-07:00
by him21sri
Thanks this worked well. I also want to know what is the best way to make the background of lower rectangle in the above image translucent or set some opacity to it.
As well as for some reason, for me the text in the black rectangle is not center aligned its touching the upper edge of the rectangle but in your case it is coming proper.
Re: Putting text in a rectangle or an overalyed image
Posted: 2017-04-18T03:05:09-07:00
by Bonzo
Try using a rgba colour instead of black: rgba\(0,0,0,0.5\)
Re: Putting text in a rectangle or an overalyed image
Posted: 2017-04-18T03:12:57-07:00
by him21sri
Ok that worked, this is essentially the alpha value is 0.5 which is making it translucent, cant we set transparency without using rgba color?
Because in many instances I might have to use colors other than black, so I will prefer putting the color name as required and setting the transparency with some other option.
Re: Putting text in a rectangle or an overalyed image
Posted: 2017-04-18T03:13:47-07:00
by him21sri
him21sri wrote: ↑2017-04-18T02:55:57-07:00
As well as for some reason, for me the text in the black rectangle is not center aligned its touching the upper edge of the rectangle but in your case it is coming proper.
What about this how can I fix for my ImageMagick version?
Re: Putting text in a rectangle or an overalyed image
Posted: 2017-04-18T03:34:34-07:00
by him21sri
Anyway I was able to set the transparency externally by using
-alpha on -channel A -evaluate set 50% +channel
But now I am stuck on another problem say if the text is small say just two letters then the text becomes very large and covers the whole width of image, cant we simply specify the font size and text stays in center and background covers the width of image as present in the sample image I shared in previous comments.
Re: Putting text in a rectangle or an overalyed image
Posted: 2017-04-18T03:41:07-07:00
by Bonzo
What about this how can I fix for my ImageMagick version?
Could be a problem with you version
You might be able to move the text a bit more with e.g. -geometry 0+5 but I am not sure it will work with label
Have a look at -annotate for more control of the text
Re: Putting text in a rectangle or an overalyed image
Posted: 2017-04-18T03:55:17-07:00
by him21sri
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.