Draw Text to fit a size
Draw Text to fit a size
Hello. I need to draw a text and make it fit a certain size(300x500). I searched on google and found only terminal commands to do it , but no answer regarding magick++ . I use drawableText, but i don't know what drawable to use in order to force the text to fit a certain rectangle.
Thanks.
Thanks.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Draw Text to fit a size
I don't know the Magick++ API. At the MagickCore level, it can be done like this:
Code: Select all
image_info=CloneImageInfo((ImageInfo *) NULL);
image_info->size = ConstantString ("300x500");
(void) strcpy(image_info->filename,"label:Hello");
images=ReadImage(image_info,exception);
snibgo's IM pages: im.snibgo.com
Re: Draw Text to fit a size
Thank You, I've reached the label solution, but I have another question. How can I change the color of the label text? fillColor for that image didn't work for me..
Re: Draw Text to fit a size
snibgo wrote:I don't know the Magick++ API. At the MagickCore level, it can be done like this:
Code: Select all
image_info=CloneImageInfo((ImageInfo *) NULL); image_info->size = ConstantString ("300x500"); (void) strcpy(image_info->filename,"label:Hello); images=ReadImage(image_info,exception);
Thank You, I've reached the label solution, but I have another question. How can I change the color of the label text? fillColor for that image didn't work for me..
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Draw Text to fit a size
Setting the fill colour after the image is created won't work. To fill with, say, Red:
Code: Select all
image_info=CloneImageInfo((ImageInfo *) NULL);
image_info->size = ConstantString ("300x500");
SetImageOption (image_info, "fill", "Red");
(void) strcpy(image_info->filename,"label:hello");
images=ReadImage(image_info,exception);
snibgo's IM pages: im.snibgo.com
Re: Draw Text to fit a size
Thank You, I'll try to translate that to magick++ .
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Draw Text to fit a size
When you find the answer, please post a code snippet here, to help others.
snibgo's IM pages: im.snibgo.com
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Draw Text to fit a size
Looking at Magick++\options.h, method "void fillColor(const Color &fillColor_)" looks likely.
snibgo's IM pages: im.snibgo.com
Re: Draw Text to fit a size
Options.h is a internal class which i cannot use in my code. For the moment I have this code:snibgo wrote:Looking at Magick++\options.h, method "void fillColor(const Color &fillColor_)" looks likely.
Code: Select all
Image img;
img.fillColor("red"); // this has no effect for the label, only for drawable objects that i draw when i use method img.draw()
img.size(Geometry(300,300));
img.backgroundColor("transparent");
img.font("Liberation-Sans-Regular");
string text = "label:" + "This is a test";
img.read(text);
Re: Draw Text to fit a size
The code i wrote earlier works fine. It didn't work at me because I wasn't using the last version of Magick++ , but libmagick++-dev . After I downloaded the last version of ImageMagick from git and compile it, both img.fillColor(Color("red")) and img.textGravity(CenterGravity); worked.
The last code is:
The last code is:
Code: Select all
Image img;
img.textGravity(CenterGravity);
img.fillColor(Color("blue"));
img.size(Geometry(300,300,0,0));
img.backgroundColor("red");
string text = "label:";
text += "This is a test";
img.read(text);
img.write("output.png");