2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % M M AAA GGGG IIIII CCCC K K %
7 % MM MM A A G I C K K %
8 % M M M AAAAA G GGG I C KKK %
9 % M M A A G G I C K K %
10 % M M A A GGGG IIIII CCCC K K %
13 % Perform "Magick" on Images via the Command Line Interface %
20 % Copyright 1999-2018 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % https://imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 % Read CLI arguments, script files, and pipelines, to provide options that
37 % manipulate images from many different formats.
44 #include "MagickWand/studio.h"
45 #include "MagickWand/MagickWand.h"
48 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 static int MagickMain(int argc,char **argv)
63 #define MagickCommandSize(name,use_metadata,command) \
64 { (name), sizeof(name)-1, (use_metadata), (command) }
66 typedef struct _CommandInfo
84 MagickCommandSize("magick", MagickFalse, MagickImageCommand),
85 MagickCommandSize("convert", MagickFalse, ConvertImageCommand),
86 MagickCommandSize("composite", MagickFalse, CompositeImageCommand),
87 MagickCommandSize("identify", MagickTrue, IdentifyImageCommand),
88 MagickCommandSize("animate", MagickFalse, AnimateImageCommand),
89 MagickCommandSize("compare", MagickTrue, CompareImagesCommand),
90 MagickCommandSize("conjure", MagickFalse, ConjureImageCommand),
91 MagickCommandSize("display", MagickFalse, DisplayImageCommand),
92 MagickCommandSize("import", MagickFalse, ImportImageCommand),
93 MagickCommandSize("mogrify", MagickFalse, MogrifyImageCommand),
94 MagickCommandSize("montage", MagickFalse, MontageImageCommand),
95 MagickCommandSize("stream", MagickFalse, StreamImageCommand)
99 client_name[MagickPathExtent],
121 MagickCoreGenesis(*argv,MagickTrue);
122 exception=AcquireExceptionInfo();
123 image_info=AcquireImageInfo();
124 GetPathComponent(argv[0],TailPath,client_name);
125 number_commands=sizeof(MagickCommands)/sizeof(MagickCommands[0]);
126 for (i=0; i < (ssize_t) number_commands; i++)
128 offset=LocaleNCompare(MagickCommands[i].client_name,client_name,
129 MagickCommands[i].extent);
133 i%=(number_commands);
134 if ((i == 0) && (argc > 1))
136 for (i=1; i < (ssize_t) number_commands; i++)
138 offset=LocaleCompare(MagickCommands[i].client_name,argv[1]);
148 metadata=(char *) NULL;
149 status=MagickCommandGenesis(image_info,MagickCommands[i].command,argc,argv,
150 MagickCommands[i].use_metadata ? &metadata : (char **) NULL,exception);
151 if (metadata != (char *) NULL)
153 (void) fputs(metadata,stdout);
154 metadata=DestroyString(metadata);
156 if (MagickCommands[i].command != CompareImagesCommand)
157 exit_code=status != MagickFalse ? 0 : 1;
160 if (status == MagickFalse)
167 option=GetImageOption(image_info,"compare:dissimilar");
168 exit_code=IsStringTrue(option) ? 1 : 0;
171 image_info=DestroyImageInfo(image_info);
172 exception=DestroyExceptionInfo(exception);
173 MagickCoreTerminus();
177 #if !defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__CYGWIN__) || defined(__MINGW32__)
178 int main(int argc,char **argv)
180 return(MagickMain(argc,argv));
183 int wmain(int argc,wchar_t *argv[])
194 utf8=NTArgvToUTF8(argc,argv);
195 status=MagickMain(argc,utf8);
196 for (i=0; i < argc; i++)
197 utf8[i]=DestroyString(utf8[i]);
198 utf8=(char **) RelinquishMagickMemory(utf8);