wanddemo.lpr 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. {
  2. Demonstration program for the ImageMagick Library
  3. This program was converted from c by: Felipe Monteiro de Carvalho
  4. Usage: Just execute the program. It will resize the image.png image
  5. on it's directory to fit (106, 80) and convert it to a jpg.
  6. Dez/2005
  7. }
  8. program wanddemo;
  9. {$mode objfpc}{$H+}
  10. uses SysUtils, magick_wand, ImageMagick;
  11. procedure ThrowWandException(wand: PMagickWand);
  12. var
  13. description: PChar;
  14. severity: ExceptionType;
  15. begin
  16. description := MagickGetException(wand, @severity);
  17. WriteLn(Format('An error ocurred. Description: %s', [description]));
  18. description := MagickRelinquishMemory(description);
  19. Abort;
  20. end;
  21. var
  22. status: MagickBooleanType;
  23. wand: PMagickWand;
  24. begin
  25. { Read an image. }
  26. MagickWandGenesis;
  27. wand := NewMagickWand;
  28. try
  29. status := MagickReadImage(wand, 'image.png');
  30. if (status = MagickFalse) then ThrowWandException(wand);
  31. { Turn the images into a thumbnail sequence. }
  32. MagickResetIterator(wand);
  33. while (MagickNextImage(wand) <> MagickFalse) do
  34. MagickResizeImage(wand, 106, 80, LanczosFilter, 1.0);
  35. { Write the image as MIFF and destroy it. }
  36. status := MagickWriteImages(wand, 'image.jpg', MagickTrue);
  37. if (status = MagickFalse) then ThrowWandException(wand);
  38. finally
  39. wand := DestroyMagickWand(wand);
  40. MagickWandTerminus;
  41. end;
  42. end.