GraphicsMagick++ draw text and auto-resize canvas

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
soyxan
Posts: 9
Joined: 2017-04-29T07:47:20-07:00
Authentication code: 1151

GraphicsMagick++ draw text and auto-resize canvas

Post by soyxan » 2017-10-19T00:51:20-07:00

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?

snibgo
Posts: 9378
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo » 2017-10-19T01:31:32-07:00

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

soyxan
Posts: 9
Joined: 2017-04-29T07:47:20-07:00
Authentication code: 1151

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

Post by soyxan » 2017-10-19T06:30:11-07:00

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...)?

snibgo
Posts: 9378
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo » 2017-10-19T06:40:47-07:00

In the way you have done it. Doesn't that work? It does for me, using IM. Maybe it doesn't in GM.
snibgo's IM pages: im.snibgo.com

soyxan
Posts: 9
Joined: 2017-04-29T07:47:20-07:00
Authentication code: 1151

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

Post by soyxan » 2017-10-19T08:28:37-07:00

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?

User avatar
fmw42
Posts: 22079
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

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

Post by fmw42 » 2017-10-19T09:51:50-07:00

Caption: or label: or pango:

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

Post Reply