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