1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#include "wand/magick_wand.h"
void DrawText(char *inputImage, char *outputImage, char *outputFormat, char *conferenceName, char *data, char *userName, char *userID) {
MagickBooleanType status;
MagickWand *magick_wand = NULL;
DrawingWand *d_wand = NULL;
PixelWand *p_wand = NULL;
magick_wand = NewMagickWand();
d_wand = NewDrawingWand();
p_wand = NewPixelWand();
// fixed data
char *user = "Utente";
char *ID = "ID";
// 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);
}
// 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 *) conferenceName);
DrawSetFontSize(d_wand,14);
DrawAnnotation(d_wand,150,15,(const unsigned char *) data);
// different font, colour and size
PixelSetColor(p_wand,"green");
DrawSetFillColor(d_wand,p_wand);
DrawSetFontSize(d_wand,20);
DrawSetFont(d_wand,"Times-Roman");
// Now draw the text
DrawAnnotation(d_wand,30,90,(const unsigned char *) user);
// same size and colour
DrawSetFont(d_wand,"Times-Roman");
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, 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();
printf("\n%s,%s,%s,%s,%s,%s\n",inputImage, outputImage, conferenceName, data, userName, userID);
}
|