Page 1 of 1

Help using AnnotateImage()

Posted: 2010-04-26T13:36:58-07:00
by jamesanderson
I've been at this for hours, trying various combinations to no avail. Anyway, please check out my code and let me know what I'm doing wrong.

Basically, I'm trying to create a new blank image and add text to it. So far I can create a blank image, but the text never gets annotated, even though AnnotateImage() returns true. The way I know this is that I convert the image to a YUV blob and dump it to a file. When I view the .yuv file using a yuv player is when I notice that there is no text on the image. The background values I setup appear, but no text. Please Help!

Code: Select all

    ImageInfo *img_info = CloneImageInfo((ImageInfo *) NULL);
    Image *new_img = new Image();
    DrawInfo *draw_info = new DrawInfo();
    MagickPixelPacket *bg = new MagickPixelPacket();
    TypeMetric metrics;
    MagickBooleanType retv = MagickFalse;
    unsigned long width = 300;
    unsigned long height = 200;
    int length1 = 0;

    char *text = new char[1024];
    strcpy(text, "blah blah blah blah blah");

    // setup text values
    draw_info->text = new char[strlen(text) * 2];
    draw_info->fill.blue = QuantumRange;
    draw_info->fill.green = 0;
    draw_info->fill.red = 0;
    draw_info->fill.opacity = 0;

    // set bg values
    bg->blue = QuantumRange;
    bg->red = QuantumRange;
    bg->green = QuantumRange;
    
    // create a new blank image
    new_img = NewMagickImage(img_info, width, height, bg);

    // copy entered text to draw info var
    strcpy(draw_info->text, text); 

    // overlay text on new image
    retv = AnnotateImage(new_img, draw_info);

    // convert new image to blob
    void* img_blob;
    (void) strcpy(img_info->filename,"text.yuv");
    img_info->colorspace = YUVColorspace;
    strcpy(img_info->magick, "YUV");
    (void) TransformImageColorspace((Image *) new_img, YUVColorspace);
    img_blob = ImageToBlob(img_info,(Image *) new_img, (size_t*) &length1 , exception);

    // output to file
    FILE *m_pf;
    m_pf = fopen("text.yuv", "ab");

    if(m_pf != NULL)
    {
        fwrite(img_blob , 1 , length1 , m_pf );
        fclose(m_pf);
    }
Thanks,
James

Re: Help using AnnotateImage()

Posted: 2010-04-26T16:53:58-07:00
by el_supremo
Which version of IM are you using?

Probably what is happening is that you haven't specified where to draw the text so it is drawn with the baseline at (0,0). This means the text will be drawn above the top of the image. Try adding this statement before the AnnotateImage().

Code: Select all

	CloneString(&draw_info->geometry,"+10+10");
Pete

Re: Help using AnnotateImage()

Posted: 2010-04-27T09:13:15-07:00
by jamesanderson
I'm using IM 6.6.0

Thanks for the suggestion, I've tested this out using a few different settings +10+10 and +55+10 and others, but nothing seems to work. Are there any other settings, like background color or opacity that could affect this?

-James

Re: Help using AnnotateImage()

Posted: 2010-04-27T09:39:20-07:00
by el_supremo
The opacity might be affecting it but you should try setting the stroke colour as well:

Code: Select all

    draw_info->stroke.blue = 0;
    draw_info->stroke.green = 0;
    draw_info->stroke.red = QuantumRange;
    draw_info->stroke.opacity = 1;
Pete

Re: Help using AnnotateImage()

Posted: 2010-04-28T11:19:42-07:00
by jamesanderson
Thanks again, but it still doesn't work.

I've tried adding stroke values, and still no text. I keep feeling there is something small that I'm missing. I did notice that I got an error/warning during the annotation process. It says something about the type.xml not being defined. Does that ring any bells?

-James

Re: Help using AnnotateImage()

Posted: 2010-04-28T19:52:03-07:00
by el_supremo
It says something about the type.xml not being defined
I haven't seen that error but it suggests that your IM installation isn't right. That file should be in the config subdirectory of your IM's installed directory.

Pete

Re: Help using AnnotateImage()

Posted: 2010-05-18T09:50:28-07:00
by jamesanderson
Thanks for your help, sorry for the late reply, I had to move on to another project. Now I'm back.

Anyway, the exact error is ConfigureWarning error: "UnableToOpenConfigureFile" 'type.xml' @ warning/configure.c/GetConfigureOptions/589

Does this ring any bells? I'm assuming that somewhere I do not have the type.xml file available. Is there any helpful documentation on where in my install this file should reside? Also, it looks like type.xml calls type-ghostscript.xml, so I should make that available as well I assume.

If anyone has had any experience with this, please let me know. Any help would be appreciated.

-James

Re: Help using AnnotateImage()

Posted: 2010-05-18T10:13:10-07:00
by fmw42
type

convert -list configure

and look at your DELEGATES line to see if it has gs (ghostscript).

Also you can create the type.xml file using Anthony's script, imagick_type_gen , at http://www.imagemagick.org/Usage/scripts/

After that you can use

convert -list font

to show all your fonts.

Re: Help using AnnotateImage()

Posted: 2010-05-19T08:34:57-07:00
by jamesanderson
That Worked!

Once type.xml was found it all worked. Thanks to everyone for their help!