[ImageMagick]
[sponsor]

The MagickWand API is the recommended interface between the C programming language and the ImageMagick image processing libraries. Unlike the MagickCore C API, MagickWand uses only a few opaque types. Accessors are available to set or get important wand attributes. A description of the MagickWand public methods are found here:

After you write your MagickWand program, compile it like this:

  cc `Wand-config --cflags --cppflags` wand.c `Wand-config --ldflags --libs`

Here is a example program that utilizes the MagickWand API to get you started, wand.c. It reads a GIF image, creates a thumbnail, and writes it to disk in the PNG image format.

  #include <stdio.h>
  #include <wand/MagickWand.h>
  
  int main(int argc,char **argv)
  {
  #define ThrowWandException(wand) \
  { \
    char \
      *description; \
   \
    ExceptionType \
      severity; \
   \
    description=MagickGetException(wand,&severity); \
    (void) fprintf(stderr,"%s %s %ld %s\n",GetMagickModule(),description); \
    description=(char *) MagickRelinquishMemory(description); \
    exit(-1); \
  }
  
    MagickBooleanType
      status;
  
    MagickWand
      *magick_wand;
  
    /*
      Read an image.
    */
    MagickWandGenesis();
    magick_wand=NewMagickWand();  
    status=MagickReadImage(magick_wand,"image.gif");
    if (status == MagickFalse)
      ThrowWandException(magick_wand);
    /*
      Turn the images into a thumbnail sequence.
    */
    MagickResetIterator(magick_wand);
    while (MagickNextImage(magick_wand) != MagickFalse)
      MagickResizeImage(magick_wand,106,80,LanczosFilter,1.0);
    /*
      Write the image as MIFF and destroy it.
    */
    status=MagickWriteImages(magick_wand,"image.png",MagickTrue);
    if (status == MagickFalse)
      ThrowWandException(magick_wand);
    magick_wand=DestroyMagickWand(magick_wand);
    MagickWandTerminus();
    return(0);
  }
 
© 1999-2006 ImageMagick Studio LLC