[magickd] Add PixelWand color setters
[magickd.git] / graphicsmagick_c / examples / convert.d
blob11a3878ee7660c5ecb5101fc1dda19f68267e56d
1 /* Copyright (C) GraphicsMagick Group 2002 - 2022 */
2 import core.stdc.stdio;
3 import core.stdc.string;
5 import graphicsmagick_c.config;
6 import graphicsmagick_c.magick;
8 extern (C) int main(int argc, char** argv)
10 Image* image = null;
12 char[MaxTextExtent] infile;
13 char[MaxTextExtent] outfile;
15 int arg = 1;
16 int exit_status = 0;
18 ImageInfo* imageInfo;
20 ExceptionInfo exception;
22 version(GMagick_Static) {}
23 else {
24 void* libgm;
26 bool success = loadGraphicsMagick(libgm);
27 if (success) {
28 puts("Successfully loaded GraphicsMagick!\n");
29 } else {
30 puts("Loaded GraphicsMagick with some errors!\n");
34 InitializeMagick(null);
35 imageInfo = CloneImageInfo(null);
36 GetExceptionInfo(&exception);
38 if (argc != 3) {
39 fprintf(stderr, "Usage: %s infile outfile\n", argv[0]);
40 fflush(stderr);
41 exit_status = 0;
42 goto program_exit;
45 // array.ptr and &array[0] are the same thing
46 strncpy(infile.ptr, argv[arg], MaxTextExtent-1);
47 arg++;
48 strncpy(&outfile[0], argv[arg], MaxTextExtent-1);
50 strcpy(imageInfo.filename.ptr, infile.ptr);
51 image = ReadImage(imageInfo, &exception);
52 if (image is null) {
53 CatchException(&exception);
54 exit_status = 1;
55 goto program_exit;
58 strcpy(image.filename.ptr, outfile.ptr);
59 if (!WriteImage(imageInfo, image)) {
60 CatchException(&exception);
61 exit_status = 1;
62 goto program_exit;
65 program_exit:
67 if (image !is null)
68 DestroyImage(image);
70 if (imageInfo !is null)
71 DestroyImageInfo(imageInfo);
73 DestroyMagick();
75 return exit_status;