Reputation: 21
Im trying to add red background under the text using Magick++. My simple code is:
Magick::Image img( Geometry(800,200), Color("white") );
img.strokeWidth(12);
img.font("Helvetica");
img.fontPointsize(font_size);
img.draw(Magick::DrawableTextUnderColor(Magick::Color("red")));
img.draw(Magick::DrawableText(25, 25, "Some text") );
img.write("file.png");
It prints text OK, but the text does not have red background. Current result is this:
However, I would like to have the text with background, something like this (background photo shopped for the example)
Upvotes: 0
Views: 1278
Reputation: 852
Here is a solution of your problem,
Image img(Geometry(800, 800), Color("white"));
img.font("Helvetica");
img.fillColor(Color("firebrick"));
img.strokeColor(Color("red"));
img.draw(Magick::DrawableText(25, 25, "Some text") );
img.write("text.png");
Upvotes: 2
Reputation: 238209
This should work. Instead of drawing things one-by-one, make a list of Drawable items, and than draw everything at once:
list<Magick::Drawable> to_draw;
to_draw.push_back(Magick::DrawableText(25, 25, "Some text"));
to_draw.push_back(Magick::DrawableTextUnderColor("red"));
img.draw(to_draw);
Upvotes: 2