core.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include <magick/MagickCore.h>
  6. int main(int argc,char **argv)
  7. {
  8. ExceptionInfo
  9. *exception;
  10. Image
  11. *image,
  12. *images,
  13. *resize_image,
  14. *thumbnails;
  15. ImageInfo
  16. *image_info;
  17. if (argc != 3)
  18. {
  19. (void) fprintf(stdout,"Usage: %s image thumbnail\n",argv[0]);
  20. exit(0);
  21. }
  22. /*
  23. Initialize the image info structure and read an image.
  24. */
  25. MagickCoreGenesis(*argv,MagickTrue);
  26. exception=AcquireExceptionInfo();
  27. image_info=CloneImageInfo((ImageInfo *) NULL);
  28. (void) strcpy(image_info->filename,argv[1]);
  29. images=ReadImage(image_info,exception);
  30. if (exception->severity != UndefinedException)
  31. CatchException(exception);
  32. if (images == (Image *) NULL)
  33. exit(1);
  34. /*
  35. Convert the image to a thumbnail.
  36. */
  37. thumbnails=NewImageList();
  38. while ((image=RemoveFirstImageFromList(&images)) != (Image *) NULL)
  39. {
  40. resize_image=ResizeImage(image,106,80,LanczosFilter,1.0,exception);
  41. if (resize_image == (Image *) NULL)
  42. MagickError(exception->severity,exception->reason,exception->description);
  43. (void) AppendImageToList(&thumbnails,resize_image);
  44. DestroyImage(image);
  45. }
  46. /*
  47. Write the image thumbnail.
  48. */
  49. (void) strcpy(thumbnails->filename,argv[2]);
  50. WriteImage(image_info,thumbnails);
  51. /*
  52. Destroy the image thumbnail and exit.
  53. */
  54. thumbnails=DestroyImageList(thumbnails);
  55. image_info=DestroyImageInfo(image_info);
  56. exception=DestroyExceptionInfo(exception);
  57. MagickCoreTerminus();
  58. return(0);
  59. }