How to set font color for caption image?

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
kaynes
Posts: 1
Joined: 2014-02-18T15:19:45-07:00
Authentication code: 6789

How to set font color for caption image?

Post 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?
Flocke
Posts: 4
Joined: 2014-02-21T06:31:18-07:00
Authentication code: 6789

Re: How to set font color for caption image?

Post 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
iSage
Posts: 14
Joined: 2015-03-02T13:03:49-07:00
Authentication code: 6789

Re: How to set font color for caption image?

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to set font color for caption image?

Post by fmw42 »

look for something like fill, (stroke or strokecolor) - just a guess since that is how it is done in command line
iSage
Posts: 14
Joined: 2015-03-02T13:03:49-07:00
Authentication code: 6789

Re: How to set font color for caption image?

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to set font color for caption image?

Post by fmw42 »

iSage
Posts: 14
Joined: 2015-03-02T13:03:49-07:00
Authentication code: 6789

Re: How to set font color for caption image?

Post by iSage »

Yep, that's the first thing i've tried
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to set font color for caption image?

Post by fmw42 »

What is your IM version? If old, perhaps you should update it. There may have been a bug in an old version.
iSage
Posts: 14
Joined: 2015-03-02T13:03:49-07:00
Authentication code: 6789

Re: How to set font color for caption image?

Post by iSage »

6.9.2.7
I'm not seeing anything related in the changelog, though
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to set font color for caption image?

Post by fmw42 »

iSage
Posts: 14
Joined: 2015-03-02T13:03:49-07:00
Authentication code: 6789

Re: How to set font color for caption image?

Post by iSage »

Yep, that's the one i've checked.
iSage
Posts: 14
Joined: 2015-03-02T13:03:49-07:00
Authentication code: 6789

Re: How to set font color for caption image?

Post 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
kenedy
Posts: 1
Joined: 2016-12-20T12:39:14-07:00
Authentication code: 1151

Re: How to set font color for caption image?

Post by kenedy »

I am facing the same problem.anyone has an idea or solution for that?
Graduated from Soran University with First Class Degree with Honours in Computer Science.
Post Reply