#include <stdio.h>
#include <stdlib.h>
#include <wand/magick-wand.h>

#define ThrowWandException(wand) \
{ \
  char *description; \
  ExceptionType severity; \
  description = MagickGetException(wand, &severity); \
  fprintf(stderr, "%s %s %lu %s\n", GetMagickModule(), description); \
  description = (char *) MagickRelinquishMemory(description); \
  exit(-1); \
}

int main(int argc, char **argv)
{
  MagickBooleanType status;
  MagickWand *wand;

  /* read image */
  MagickWandGenesis();
  wand = NewMagickWand();
  status = MagickReadImage(wand, "in.png");
  if (status == MagickFalse)
    ThrowWandException(wand);

  /* crop twice */
  MagickCropImage(wand, 300, 300, 50, 50);
  MagickCropImage(wand, 250, 250, 0, 0);

  /* write the image then destroy it */
  status = MagickWriteImage(wand, "out.png");
  if (status == MagickFalse)
    ThrowWandException(wand);
  wand = DestroyMagickWand(wand);
  MagickWandTerminus();

  return 0;
}
