Putting text in a rectangle or an overalyed image
Putting text in a rectangle or an overalyed image
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.
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.
-
- 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
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.
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.
snibgo's IM pages: im.snibgo.com
Re: Putting text in a rectangle or an overalyed image
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.
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.
- 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
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
Windows
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/
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
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
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
- 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
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?
What is a bookmark type small image?
Re: Putting text in a rectangle or an overalyed image
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
- 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
Here is a simple example:
Input:
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
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.
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
Try using a rgba colour instead of black: rgba\(0,0,0,0.5\)
Re: Putting text in a rectangle or an overalyed image
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.
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
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.
-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
Could be a problem with you versionWhat about this how can I fix for my ImageMagick 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
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.