DrawAnnotation problem

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
erotavlas_turbo

DrawAnnotation problem

Post by erotavlas_turbo »

Hi all,

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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: DrawAnnotation problem

Post by magick »

You are triggering an assert. In the wand/drawing-wand.c code we have:
  • WandExport void DrawAnnotation(DrawingWand *wand,const double x,const double y,
    const unsigned char *text)
    {
    ...
    assert(text != (const unsigned char *) NULL);
Text must be NULL for this assert to complain suggesting unequivocally that member_list->callername is NULL.
erotavlas_turbo

Re: DrawAnnotation problem

Post by erotavlas_turbo »

ok, thank.

Now I have the same problem with different variable. I have the same data structure with a field int callerID type

DrawAnnotation(d_wand,x,y,(const unsigned char *) callerID)

I get Segmentation Fault

If i write the same data to a text file, the program will work well
fprintf(file,"CallerName %s, callerID);

the code is the following

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "wand/magick_wand.h"



#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); \
}

void DrawText(char* inputImage, char* outputImage, char* outputFormat, char* time) {

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

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

	// initialize MagickWand environment
	MagickWandGenesis();
	
        // read the image. 
        status = MagickReadImage(magick_wand, inputImage);
	if (status == MagickFalse) {
		printf("Unable to Read\n");
		ThrowWandException(magick_wand);
	}
    
	// scale the image dimension
	if (strcmp(outputFormat,"CIF") == 0) 
		status = MagickScaleImage(magick_wand, 352, 288);
	else if (strcmp(outputFormat,"QCIF") == 0) 
		status = MagickScaleImage(magick_wand, 176, 144);
	else 
		printf("Invalid output format %s\n", outputFormat);

	if (status == MagickFalse) {
		printf("Unable to Scale\n");
		ThrowWandException(magick_wand);
	}
		
	// fixed data
	char* user = "Utente";
	char* ID = "ID";
					
	// set up the font size and colour
        DrawSetFont(d_wand,"Helvetica");
        PixelSetColor(p_wand,"black");
        DrawSetFillColor(d_wand,p_wand);
        DrawSetFontSize(d_wand,32);
        // now draw conference name
	DrawAnnotation(d_wand,10,50,(const unsigned char *) user);

	DrawSetFontSize(d_wand,14);
	DrawAnnotation(d_wand,150,15,(const unsigned char *) time);
        // different font, colour and size
        PixelSetColor(p_wand,"green");
        DrawSetFillColor(d_wand,p_wand);
        DrawSetFontSize(d_wand,25);
        DrawSetFont(d_wand,"Times-Roman");
	// now draw the text
        DrawAnnotation(d_wand,30,90,(const unsigned char *) user);
	DrawAnnotation(d_wand,180,90,(const unsigned char *) ID);
	//char * total = (const unsigned char*) conf->membercount;
	//DrawAnnotation(d_wand,240,90,(const unsigned char *) conf->membercount );
	
	PixelSetColor(p_wand,"black");
        DrawSetFillColor(d_wand,p_wand);
        DrawSetFontSize(d_wand,23);
	int id = 10;
		FILE *file;
		file = fopen("/home/tore/Scrivania/prova/file.txt","w");
		fprintf(file,"%d\n", id);
		DrawAnnotation(d_wand,150,200,(const unsigned char *) id);
		

	fclose(file);
	

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

        // and write it
        status = MagickWriteImage(magick_wand, outputImage);

        /* 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();
	
}


int main() {

	char *inputImage = "/home/tore/Scrivania/prova/Asterisk_logo.jpg";
	char *outputImage = "/home/tore/Scrivania/prova/prova.jpg"; 
	char *outputFormat = "CIF";
	char *time = "2/12/2009 17:03";
	// draw the text over the input image
	DrawText(inputImage, outputImage, outputFormat, time);
	

	
	return 0;
}

I think that there isn't possible to write a int type in text field.

Thank you
erotavlas_turbo

Re: DrawAnnotation problem

Post by erotavlas_turbo »

I have solved with the following trick

Code: Select all

char buffer[50];
			
       			
			sprintf( buffer, "%d", member_list->id );	
        		DrawAnnotation(d_wand,x+175,y,(const unsigned char *) buffer );
:D
Post Reply