[magickd] Add PixelWand color setters
[magickd.git] / graphicsmagick_c / examples / rotate.d
blob766c01380c176894efdd75a6116663e21e979d0a
1 // Copyright (C) GraphicsMagick Group 2002 - 2022
2 import core.stdc.stdio;
4 import graphicsmagick_c.config;
5 import graphicsmagick_c.wand.wand_api;
7 extern (C) int main(int argc, char** argv)
9 MagickWand* magick_wand;
10 MagickPassFail status = MagickPass;
12 char* infile, outfile;
14 if (argc != 3) {
15 fprintf(stderr, "Usage: %s infile outfile\n", argv[0]);
16 return 1;
19 infile = argv[1];
20 outfile = argv[2];
22 // Load dynamic bindings if required
23 version (GMagick_Static) {}
24 else {
25 void* libgm;
26 void* libgmwand;
28 bool success = loadGraphicsMagick(libgm);
29 if (success) {
30 puts("Successfully loaded GraphicsMagick!\n");
31 } else {
32 puts("Loaded GraphicsMagick with some errors!\n");
35 success = loadGraphicsMagickWand(libgmwand);
36 if (success) {
37 puts("Successfully loaded GraphicsMagickWand!\n");
38 } else {
39 puts("Loaded GraphicsMagikcWand with some errors!\n");
43 // Initialize GraphicsMagick API
44 InitializeMagick(*argv);
46 // Allocate Wand handle
47 magick_wand = NewMagickWand();
49 // Read input image file
50 if (status == MagickPass) {
51 status = MagickReadImage(magick_wand, infile);
54 // Rotate the image clockwise 30 degrees with a black background
55 if (status == MagickPass) {
56 PixelWand* background;
57 background = NewPixelWand();
58 PixelSetColor(background, "#000000");
59 status = MagickRotateImage(magick_wand, background, 30);
60 DestroyPixelWand(background);
63 // Write output file
64 if (status == MagickPass) {
65 status = MagickWriteImage(magick_wand, outfile);
68 // Diagnose any error
69 if (status != MagickPass) {
70 char* description;
71 ExceptionType severity;
73 description = MagickGetException(magick_wand, &severity);
74 fprintf(stderr, "%.1024s (severity %d)\n", description, severity);
77 // Release Wand handle
78 DestroyMagickWand(magick_wand);
80 // Destroy GraphicsMagick API
81 DestroyMagick();
83 return (status == MagickPass ? 0 : 1);