Page 2 of 2

Re: C code for command CONVERT

Posted: 2009-12-04T00:51:36-07:00
by erotavlas_turbo
please can you tell me the differences?So i can learn...

thank

Re: C code for command CONVERT

Posted: 2009-12-04T03:55:27-07:00
by erotavlas_turbo
I'm trying to change the font from Helvetiva to Arial, Courier New or Time New Roman but it doesn't change.
There is no error so the font exists.

Thank

Re: C code for command CONVERT

Posted: 2009-12-04T08:08:06-07:00
by el_supremo
Here's my version of the code. I've added comments with //*** where my changes occur.
One thing to note. I run this on Windows XP Pro and compile it as a windows program, not a DOS command line program.

Pete

Code: Select all

//*** Don't need these if ThrowWandException isn't defined
//    #include <stdio.h>
//    #include <stdlib.h>
//    #include <iostream>

    #include <windows.h>
    #include "wand/magick_wand.h"

//*** I'm using C so I don't need this
//    using namespace std;

    //#define ThrowWandException(wand) \
    //{ \
    //  char \
    //    *description; \
    // \
    //  ExceptionType \
    //    severity; \
    // \
    //  description=MagickGetException(wand,&severity); \
    //  (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); \
    //  description=(char *) MagickRelinquishMemory(description); \
    //  exit(-1); \
    //}

//*** The name DrawText conflicts with a Windows function of that name
    void u_DrawText(char * nome_conferenza, char * data, char * nome_utente, char * ID_utente) {

       MagickBooleanType status;
        MagickWand *magick_wand = NULL;
        DrawingWand *d_wand = NULL;
        PixelWand *p_wand = NULL;

//*** C requires these two to be in the declaration header
       char * utente = "Utente";
       char * ID = "ID";

        magick_wand = NewMagickWand();
        d_wand = NewDrawingWand();
        p_wand = NewPixelWand();



       // initialize MagickWand environment
       MagickWandGenesis();
       
        // Read the image. Change "logo:" to the name of your input image file
	   status = MagickReadImage(magick_wand,"logo:");
       //if (status == MagickFalse)
       //ThrowWandException(magick_wand);
       
       // Set up the font size and colour
        DrawSetFont(d_wand,"Helvetica");
        PixelSetColor(p_wand,"black");
        DrawSetFillColor(d_wand,p_wand);
        DrawSetFontSize(d_wand,28);
        // Now draw the text
       DrawAnnotation(d_wand,10,50,(const unsigned char *) nome_conferenza);

       DrawSetFontSize(d_wand,14);
       DrawAnnotation(d_wand,150,15,(const unsigned char *) data);
        // same font - different colour and size
        PixelSetColor(p_wand,"yellow");
        DrawSetFillColor(d_wand,p_wand);
        DrawSetFontSize(d_wand,20);
        // Now draw the text
        DrawAnnotation(d_wand,30,90,(const unsigned char *) utente);

        // same font, size and colour
        DrawAnnotation(d_wand,180,90,(const unsigned char *) ID);

        // Draw the image on to the magick_wand
        MagickDrawImage(magick_wand,d_wand);

        // and write it
        status = MagickWriteImage(magick_wand,"logo_problem_text.jpg");

        /* Clean up */
       // if (status == MagickFalse)
    //    ThrowWandException(magick_wand);
        if(magick_wand) magick_wand = DestroyMagickWand(magick_wand);
        if(d_wand) d_wand = DestroyDrawingWand(d_wand);
        if(p_wand) p_wand = DestroyPixelWand(p_wand);
       
       // terminate the MagickWand environment
       MagickWandTerminus();
    }

//*** This just makes it work with my testing program
//    void main() {
void test_wand(LPTSTR lpCmdLine)
{          
       char * nome_conferenza = "Conferenza Prova";
       char * data = "2/12/2009 17:03";
       char * nome_utente = "cane";
       char * ID_utente = "3";
       u_DrawText(nome_conferenza, data, nome_utente, ID_utente);

//*** I don't need this
//       system ("Pause");

    }

Re: C code for command CONVERT

Posted: 2009-12-04T09:21:54-07:00
by erotavlas_turbo
Thank you very much for your help!!! I have nearly finished my "work"...the last question is about font.

I'm trying to change the font from Helvetiva to Arial, Courier New or Time New Roman but it doesn't change.
There is no error so the font exists.Why doesn't it change?

Thank

Re: C code for command CONVERT

Posted: 2009-12-04T10:58:55-07:00
by el_supremo
For different fonts all you should need to change is the name of the font in this statement: DrawSetFont(d_wand,"Helvetica");
E.g. I changed it to DrawSetFont(d_wand,"Times-New-Roman"); and the font changed in the output image.
But the way that Linux and Windows names their fonts is different. The Times New Roman font in Windows is named Times-New-Roman (and any other font with a space in its name always has the space replaced by a hyphen). I haven't used fonts on Linux so I don't know how they're named or if those fonts exist. You may also find that Linux is pickier about upper and lower case in the names.
To get a list of the fonts that IM sees on each system use this command:

Code: Select all

identify -list font
Pete

Re: C code for command CONVERT

Posted: 2009-12-09T01:29:47-07:00
by erotavlas_turbo
ok thank you, I'm very happy.

Bye

Re: C code for command CONVERT

Posted: 2010-01-22T06:27:22-07:00
by erotavlas_turbo
Hi Pete,

I'm writing a C code that use the following method:

DrawAnnotation(d_wand,x,y,(const unsigned char *) member_list->callername), where member_list is data structure with char* callername field.

When i run the program I get the following error:

Code: Select all

asterisk: wand/drawing-wand.c:770: DrawAnnotation: Assertion `text != (const unsigned char *) ((void *)0)' failed.
If i write the same data to a text file, the program will work well
fprintf(file,"CallerName %s, member_list->callername);

Can you help me?

Thank you in advance