Page 1 of 1
How to set font color for caption image?
Posted: 2014-02-18T15:28:38-07:00
by kaynes
I'm trying too generate one image with caption:
//Command line
convert composite.png -gravity south -size 70x -font Montserrat-Bold.tff -pointsize 8 -fill "#cecece" -background transparent caption:"My amazing caption" -composite result.png
This work fine!
And my code representation is:
Code: Select all
MagickWand *mwc = NULL;
DrawingWand *dw = NULL;
PixelWand *pw = NULL;
mwc = NewMagickWand();
dw = NewDrawingWand();
pw = NewPixelWand();
MagickSetGravity(mwc, SouthGravity);
MagickSetSize(mwc, 70,20);
MagickSetFont(mwc, "Montserrat-Bold.ttf");
MagickSetPointsize(mwc, 8);
PixelSetColor(pw, "#cecece");
//I can set the Background color but what about the font color?
PixelSetColor(pw, "transparent");
MagickSetBackgroundColor(mwc, pw);
MagickReadImage(mwc, "caption: My amazing caption");
MagickWriteImage(mwc, "final.png");
Anyone knows to "fill" the color for the font?
Re: How to set font color for caption image?
Posted: 2014-02-21T07:13:04-07:00
by Flocke
What do you mean by "fill"?
If you are trying to get a text on an image I would use the MagickAnnotateImage function like this:
1. read your image into the MagickWand magick_wand then just do something like this
Code: Select all
double angle, x,y: //position of the capture and angle of the capture
p_wand = NewPixelWand();
d_wand = NewDrawingWand();
angle = 0;
x = 100;
y = 100;
PixelSetColor(p_wand,"red");
DrawSetFillColor(d_wand,p_wand);
MagickAnnotateImage(magick_wand,d_wand,x,y,angle,"Bingo");
This will write the word "Bingo" in the color red at 100,100 pixels from the upper left corner of your image...
Is this what you want?
greetings,
Flocke
edit:
If you want you can make the font bigger with
DrawSetFontSize(d_wand, x);
x = size of the font. 30 is still
Re: How to set font color for caption image?
Posted: 2016-10-27T14:16:25-07:00
by iSage
Sorry for bumping old thread, but i have same problem.
Example:
Code: Select all
#include <stdio.h>
#include <string.h>
#include <wand/magick_wand.h>
int main(void)
{
MagickWandGenesis();
MagickWand* m_wand = NewMagickWand();
MagickSetSize(m_wand, 100, 100);
MagickSetPointsize(m_wand, 31);
if (MagickReadImage(m_wand, "caption:hello world") != MagickTrue)
{
ExceptionType severity;
printf("error: %s\n",MagickGetException(m_wand, &severity));
}
MagickWriteImage(m_wand, "test.jpg");
}
I can set background color by using MagickSetBackgroundColor before loading pseudo-image. But how do i set text color?
I'm using pseuso-image because of "caption:" ability to auto-split text based on image width, and don't really want to deal with MagickQueryFontMetrics and manual splitting
Re: How to set font color for caption image?
Posted: 2016-10-27T15:37:28-07:00
by fmw42
look for something like fill, (stroke or strokecolor) - just a guess since that is how it is done in command line
Re: How to set font color for caption image?
Posted: 2016-10-27T15:41:45-07:00
by iSage
On the command line it's done via -fill, according to docs. Yet, none of *Fill* methods seems to work.
I've tried setting stroke color too, but to no avail
Re: How to set font color for caption image?
Posted: 2016-10-27T15:54:08-07:00
by fmw42
Re: How to set font color for caption image?
Posted: 2016-10-27T15:56:50-07:00
by iSage
Yep, that's the first thing i've tried
Re: How to set font color for caption image?
Posted: 2016-10-27T17:42:28-07:00
by fmw42
What is your IM version? If old, perhaps you should update it. There may have been a bug in an old version.
Re: How to set font color for caption image?
Posted: 2016-10-28T00:34:25-07:00
by iSage
6.9.2.7
I'm not seeing anything related in the changelog, though
Re: How to set font color for caption image?
Posted: 2016-10-28T00:35:46-07:00
by fmw42
Re: How to set font color for caption image?
Posted: 2016-10-28T00:45:07-07:00
by iSage
Yep, that's the one i've checked.
Re: How to set font color for caption image?
Posted: 2016-10-28T01:15:16-07:00
by iSage
Digging deeper: it looks like "caption:" gets info about colors, etc. from Image -> ImageInfo, but wand methods operate on DrawingWand, which in case of Annotate you just pass along, but in case of "caption:" i don't really know what to do
Re: How to set font color for caption image?
Posted: 2016-12-20T20:56:49-07:00
by kenedy
I am facing the same problem.anyone has an idea or solution for that?