1 #include <stdio.h> 2 #include <MagickWand/MagickWand.h> 3 4 /* Simplify the exception handling 5 * technically we should abort the program if 6 * severity >= ErrorException 7 */ 8 void ThrowWandException(MagickWand *wand) 9 { char 10 *description; 11 12 ExceptionType 13 severity; 14 15 description=MagickGetException(wand,&severity); 16 (void) fprintf(stderr,"%s %s %lu %s\n",GetMagickModule(),description); 17 description=(char *) MagickRelinquishMemory(description); 18 } 19 20 /* useful function especially after appending two wands together */ 21 #define SwapWands(a,b) { MagickWand *tmp=a; a=b; b=tmp; } 22 23 int main(int argc, char *argv[]) 24 { 25 MagickWand 26 *wand, /* red image wand */ 27 *input, /* red image wand */ 28 *output; 29 30 MagickBooleanType 31 status; 32 33 printf("Add 3 sets of image using settings: none, first, last\n"); 34 printf("Result shoud be: 345 012 678\n"); 35 36 MagickWandGenesis(); 37 38 wand = NewMagickWand(); 39 input = NewMagickWand(); 40 41 status = MagickReadImage(input, "font_0.gif" ) 42 && MagickReadImage(input, "font_1.gif" ) 43 && MagickReadImage(input, "font_2.gif" ); 44 if (status == MagickFalse) 45 ThrowWandException(input); 46 47 status = MagickAddImage(wand, input); 48 if (status == MagickFalse) 49 ThrowWandException(wand); 50 51 ClearMagickWand(input); 52 status = MagickReadImage(input, "font_3.gif" ) 53 && MagickReadImage(input, "font_4.gif" ) 54 && MagickReadImage(input, "font_5.gif" ); 55 if (status == MagickFalse) 56 ThrowWandException(input); 57 58 MagickSetFirstIterator(wand); 59 status = MagickAddImage(wand, input); 60 if (status == MagickFalse) 61 ThrowWandException(wand); 62 63 ClearMagickWand(input); 64 status = MagickReadImage(input, "font_6.gif" ) 65 && MagickReadImage(input, "font_7.gif" ) 66 && MagickReadImage(input, "font_8.gif" ); 67 if (status == MagickFalse) 68 ThrowWandException(input); 69 70 MagickSetLastIterator(wand); 71 status = MagickAddImage(wand, input); 72 if (status == MagickFalse) 73 ThrowWandException(wand); 74 input=DestroyMagickWand(input); 75 76 /* append all images together to create the output wand */ 77 MagickResetIterator(wand); /* append all images */ 78 output = MagickAppendImages(wand,MagickFalse); 79 wand = DestroyMagickWand(wand); /* finished - could swap here */ 80 81 /* Final output */ 82 status = MagickWriteImage(output,"show:"); 83 if (status == MagickFalse) 84 ThrowWandException(output); 85 86 output = DestroyMagickWand(output); 87 88 MagickWandTerminus(); 89 } 90 91