Page 1 of 1

GraphicsMagick++ draw text and auto-resize canvas

Posted: 2017-10-19T00:51:20-07:00
by soyxan
I am planning to generate an image with Magick++ that have some text and I want the image canvas resized automatically based on the text drawn.

This is my code:

Code: Select all

bool LoadText(const std::string& text, const std::string& fontface, int pointsize, Magick::Color color) {

    image = Magick::Image( Magick::Geometry(1,1), Magick::Color("black"));
    image.font(fontface);
    image.fillColor(color);
    image.strokeColor(color);
    image.fontPointsize(pointsize);
    image.read("CAPTION:" + text);
    //image.annotate(text,CenterGravity);
    return true;
}
With "annotate()" the canvas is not resized but the text color and background is right.

If I use "CAPTION:" protocol the canvas is resized but the fontcolor and background color is not respected.

What am I doing wrong?

Re: GraphicsMagick++ draw text and auto-resize canvas

Posted: 2017-10-19T01:31:32-07:00
by snibgo
GraphicsMagick (GM) isn't ImageMagick (IM), so you are asking in the wrong place.

In IM, "caption:" creates a new image. It doesn't resize anything, it creates a new image. By contrast, "annotate" writes text on an image that must already exist. It also doesn't resize anything.

To do what you want, use:

Code: Select all

Magick::Image image = Magick::Image( );
... to declare the image, then "caption:".

But GM may be different.

Re: GraphicsMagick++ draw text and auto-resize canvas

Posted: 2017-10-19T06:30:11-07:00
by soyxan
But with "CAPTION:" protocol I can just put text as a parameter ("CAPTION:Hello this a text"), how can I specify the text porpierties (color, font, size, etc...)?

Re: GraphicsMagick++ draw text and auto-resize canvas

Posted: 2017-10-19T06:40:47-07:00
by snibgo
In the way you have done it. Doesn't that work? It does for me, using IM. Maybe it doesn't in GM.

Re: GraphicsMagick++ draw text and auto-resize canvas

Posted: 2017-10-19T08:28:37-07:00
by soyxan
And do you know any other way to draw an image with a text, having the image the exact size to fit all the text?

Re: GraphicsMagick++ draw text and auto-resize canvas

Posted: 2017-10-19T09:51:50-07:00
by fmw42
Caption: or label: or pango:

See http://www.imagemagick.org/Usage/text/