50#include "MagickWand/studio.h"
51#include "MagickWand/MagickWand.h"
52#include "MagickWand/mogrify-private.h"
53#include "MagickCore/string-private.h"
93static MagickBooleanType IdentifyUsage(
void)
97 " -debug events display copious debugging information\n"
98 " -help print program options\n"
99 " -list type print a list of supported option arguments\n"
100 " -log format format of debugging information\n"
101 " -version print version information",
103 " -auto-orient automagically orient (rotate) image\n"
104 " -channel mask set the image channel mask\n"
105 " -grayscale method convert image to grayscale\n"
106 " -negate replace every pixel with its complementary color",
108 " -alpha option on, activate, off, deactivate, set, opaque, copy\n"
109 " transparent, extract, background, or shape\n"
110 " -antialias remove pixel-aliasing\n"
111 " -authenticate password\n"
112 " decipher image with this password\n"
113 " -clip clip along the first path from the 8BIM profile\n"
114 " -clip-mask filename associate a clip mask with the image\n"
115 " -clip-path id clip along a named path from the 8BIM profile\n"
116 " -colorspace type alternate image colorspace\n"
117 " -crop geometry cut out a rectangular region of the image\n"
118 " -define format:option\n"
119 " define one or more image format options\n"
120 " -density geometry horizontal and vertical density of the image\n"
121 " -depth value image depth\n"
122 " -endian type endianness (MSB or LSB) of the image\n"
123 " -extract geometry extract area from image\n"
124 " -features distance analyze image features (e.g. contrast, correlation)\n"
125 " -format \"string\" output formatted image characteristics\n"
126 " -fuzz distance colors within this distance are considered equal\n"
127 " -gamma value of gamma correction\n"
128 " -interlace type type of image interlacing scheme\n"
129 " -interpolate method pixel color interpolation method\n"
130 " -limit type value pixel cache resource limit\n"
131 " -matte store matte channel if the image has one\n"
132 " -moments report image moments\n"
133 " -monitor monitor progress\n"
134 " -ping efficiently determine image attributes\n"
135 " -precision value maximum number of significant digits to print\n"
136 " -quiet suppress all warning messages\n"
137 " -regard-warnings pay attention to warning messages\n"
138 " -respect-parentheses settings remain in effect until parenthesis boundary\n"
139 " -sampling-factor geometry\n"
140 " horizontal and vertical sampling factor\n"
141 " -seed value seed a new sequence of pseudo-random numbers\n"
142 " -set attribute value set an image attribute\n"
143 " -size geometry width and height of image\n"
144 " -strip strip image of all profiles and comments\n"
145 " -unique display the number of unique colors in the image\n"
146 " -units type the units of image resolution\n"
147 " -verbose print detailed information about the image\n"
148 " -virtual-pixel method\n"
149 " virtual pixel access method";
151 ListMagickVersion(stdout);
152 (void) printf(
"Usage: %s [options ...] file [ [options ...] "
153 "file ... ]\n",GetClientName());
154 (void) printf(
"\nImage Settings:\n");
155 (void) puts(settings);
156 (void) printf(
"\nImage Operators:\n");
157 (void) puts(operators);
158 (void) printf(
"\nMiscellaneous Options:\n");
159 (void) puts(miscellaneous);
161 "\nBy default, the image format of 'file' is determined by its magic\n");
163 "number. To specify a particular image format, precede the filename\n");
165 "with an image format name and a colon (i.e. ps:image) or specify the\n");
167 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
168 (void) printf(
"'-' for standard input or output.\n");
172WandExport MagickBooleanType IdentifyImageCommand(ImageInfo *image_info,
173 int argc,
char **argv,
char **metadata,ExceptionInfo *exception)
175#define DestroyIdentify() \
177 DestroyImageStack(); \
178 for (i=0; i < (ssize_t) argc; i++) \
179 argv[i]=DestroyString(argv[i]); \
180 argv=(char **) RelinquishMagickMemory(argv); \
182#define ThrowIdentifyException(asperity,tag,option) \
184 char *message = GetExceptionMessage(errno); \
185 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag, \
186 "`%s'",option == (char *) NULL ? message : option); \
187 message=DestroyString(message); \
189 return(MagickFalse); \
191#define ThrowIdentifyInvalidArgumentException(option,argument) \
193 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
194 "InvalidArgument","'%s': %s",option,argument); \
196 return(MagickFalse); \
207 image_stack[MaxImageStackDepth+1];
230 assert(image_info != (ImageInfo *) NULL);
231 assert(image_info->signature == MagickCoreSignature);
232 assert(exception != (ExceptionInfo *) NULL);
233 if (IsEventLogging() != MagickFalse)
234 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
238 if ((LocaleCompare(
"version",option+1) == 0) ||
239 (LocaleCompare(
"-version",option+1) == 0))
241 ListMagickVersion(stdout);
247 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
248 "MissingArgument",
"%s",
"");
249 (void) IdentifyUsage();
257 option=(
char *) NULL;
259 respect_parentheses=MagickFalse;
264 ReadCommandlLine(argc,&argv);
265 status=ExpandFilenames(&argc,&argv);
266 if (status == MagickFalse)
267 ThrowIdentifyException(ResourceLimitError,
"MemoryAllocationFailed",
269 image_info->ping=MagickTrue;
270 for (i=1; i < (ssize_t) argc; i++)
273 if (LocaleCompare(option,
"(") == 0)
275 FireImageStack(MagickFalse,MagickTrue,pend);
276 if (k == MaxImageStackDepth)
277 ThrowIdentifyException(OptionError,
"ParenthesisNestedTooDeeply",
282 if (LocaleCompare(option,
")") == 0)
284 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
286 ThrowIdentifyException(OptionError,
"UnableToParseExpression",option);
290 if (IsCommandOption(option) == MagickFalse)
304 FireImageStack(MagickFalse,MagickFalse,pend);
305 identify_info=CloneImageInfo(image_info);
306 identify_info->verbose=MagickFalse;
308 if ((LocaleCompare(filename,
"--") == 0) && (i < ((ssize_t) argc-1)))
310 if (identify_info->ping != MagickFalse)
311 images=PingImages(identify_info,filename,exception);
313 images=ReadImages(identify_info,filename,exception);
314 identify_info=DestroyImageInfo(identify_info);
315 status&=(MagickStatusType) (images != (Image *) NULL) &&
316 (exception->severity < ErrorException);
317 if (images == (Image *) NULL)
319 AppendImageStack(images);
320 FinalizeImageSettings(image_info,image,MagickFalse);
322 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
324 if (image->scene == 0)
325 image->scene=count++;
326 if (format == (
char *) NULL)
328 (void) IdentifyImage(image,stdout,image_info->verbose,exception);
331 if (metadata != (
char **) NULL)
336 text=InterpretImageProperties(image_info,image,format,exception);
337 if (text == (
char *) NULL)
338 ThrowIdentifyException(ResourceLimitError,
339 "MemoryAllocationFailed",(
char *) NULL);
340 (void) ConcatenateString(&(*metadata),text);
341 text=DestroyString(text);
344 RemoveAllImageStack();
347 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
350 *option_info = GetCommandOptionInfo(option);
352 if (option_info != (
const OptionInfo *) NULL)
354 CommandOptionFlags option_type = (CommandOptionFlags)
356 if ((option_type & (SimpleOperatorFlag | ListOperatorFlag)) != 0)
357 image_info->ping=MagickFalse;
364 if (LocaleCompare(
"alpha",option+1) == 0)
372 if (i == (ssize_t) argc)
373 ThrowIdentifyException(OptionError,
"MissingArgument",option);
374 type=ParseCommandOption(MagickAlphaChannelOptions,MagickFalse,
377 ThrowIdentifyException(OptionError,
378 "UnrecognizedAlphaChannelOption",argv[i]);
381 if (LocaleCompare(
"antialias",option+1) == 0)
383 if (LocaleCompare(
"authenticate",option+1) == 0)
388 if (i == (ssize_t) argc)
389 ThrowIdentifyException(OptionError,
"MissingArgument",option);
392 if (LocaleCompare(
"auto-orient",option+1) == 0)
394 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
398 if (LocaleCompare(
"cache",option+1) == 0)
403 if (i == (ssize_t) argc)
404 ThrowIdentifyException(OptionError,
"MissingArgument",option);
405 if (IsGeometry(argv[i]) == MagickFalse)
406 ThrowIdentifyInvalidArgumentException(option,argv[i]);
409 if (LocaleCompare(
"channel",option+1) == 0)
417 if (i == (ssize_t) argc)
418 ThrowIdentifyException(OptionError,
"MissingArgument",option);
419 channel=ParseChannelOption(argv[i]);
421 ThrowIdentifyException(OptionError,
"UnrecognizedChannelType",
425 if (LocaleCompare(
"clip",option+1) == 0)
427 if (LocaleCompare(
"clip-mask",option+1) == 0)
432 if (i == (ssize_t) argc)
433 ThrowIdentifyException(OptionError,
"MissingArgument",option);
436 if (LocaleCompare(
"clip-path",option+1) == 0)
439 if (i == (ssize_t) argc)
440 ThrowIdentifyException(OptionError,
"MissingArgument",option);
443 if (LocaleCompare(
"colorspace",option+1) == 0)
451 if (i == (ssize_t) argc)
452 ThrowIdentifyException(OptionError,
"MissingArgument",option);
453 colorspace=ParseCommandOption(MagickColorspaceOptions,
454 MagickFalse,argv[i]);
456 ThrowIdentifyException(OptionError,
"UnrecognizedColorspace",
460 if (LocaleCompare(
"crop",option+1) == 0)
465 if (i == (ssize_t) argc)
466 ThrowIdentifyException(OptionError,
"MissingArgument",option);
467 if (IsGeometry(argv[i]) == MagickFalse)
468 ThrowIdentifyInvalidArgumentException(option,argv[i]);
471 if (LocaleCompare(
"concurrent",option+1) == 0)
473 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
477 if (LocaleCompare(
"debug",option+1) == 0)
485 if (i == (ssize_t) argc)
486 ThrowIdentifyException(OptionError,
"MissingArgument",option);
487 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
489 ThrowIdentifyException(OptionError,
"UnrecognizedEventType",
491 (void) SetLogEventMask(argv[i]);
494 if (LocaleCompare(
"define",option+1) == 0)
497 if (i == (ssize_t) argc)
498 ThrowIdentifyException(OptionError,
"MissingArgument",option);
504 define=GetImageOption(image_info,argv[i]);
505 if (define == (
const char *) NULL)
506 ThrowIdentifyException(OptionError,
"NoSuchOption",argv[i]);
509 if (LocaleNCompare(
"identify:locate",argv[i],15) == 0)
510 image_info->ping=MagickFalse;
513 if (LocaleCompare(
"density",option+1) == 0)
518 if (i == (ssize_t) argc)
519 ThrowIdentifyException(OptionError,
"MissingArgument",option);
520 if (IsGeometry(argv[i]) == MagickFalse)
521 ThrowIdentifyInvalidArgumentException(option,argv[i]);
524 if (LocaleCompare(
"depth",option+1) == 0)
529 if (i == (ssize_t) argc)
530 ThrowIdentifyException(OptionError,
"MissingArgument",option);
531 if (IsGeometry(argv[i]) == MagickFalse)
532 ThrowIdentifyInvalidArgumentException(option,argv[i]);
535 if (LocaleCompare(
"duration",option+1) == 0)
540 if (i == (ssize_t) argc)
541 ThrowIdentifyException(OptionError,
"MissingArgument",option);
542 if (IsGeometry(argv[i]) == MagickFalse)
543 ThrowIdentifyInvalidArgumentException(option,argv[i]);
546 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
550 if (LocaleCompare(
"endian",option+1) == 0)
558 if (i == (ssize_t) argc)
559 ThrowIdentifyException(OptionError,
"MissingArgument",option);
560 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,
563 ThrowIdentifyException(OptionError,
"UnrecognizedEndianType",
567 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
571 if (LocaleCompare(
"features",option+1) == 0)
576 if (i == (ssize_t) argc)
577 ThrowIdentifyException(OptionError,
"MissingArgument",option);
578 if (IsGeometry(argv[i]) == MagickFalse)
579 ThrowIdentifyInvalidArgumentException(option,argv[i]);
582 if (LocaleCompare(
"format",option+1) == 0)
584 format=(
char *) NULL;
588 if (i == (ssize_t) argc)
589 ThrowIdentifyException(OptionError,
"MissingArgument",option);
591 image_info->ping=MagickFalse;
594 if (LocaleCompare(
"fuzz",option+1) == 0)
599 if (i == (ssize_t) argc)
600 ThrowIdentifyException(OptionError,
"MissingArgument",option);
601 if (IsGeometry(argv[i]) == MagickFalse)
602 ThrowIdentifyInvalidArgumentException(option,argv[i]);
605 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
609 if (LocaleCompare(
"gamma",option+1) == 0)
612 if (i == (ssize_t) argc)
613 ThrowIdentifyException(OptionError,
"MissingArgument",option);
614 if (IsGeometry(argv[i]) == MagickFalse)
615 ThrowIdentifyInvalidArgumentException(option,argv[i]);
618 if (LocaleCompare(
"grayscale",option+1) == 0)
626 if (i == (ssize_t) argc)
627 ThrowIdentifyException(OptionError,
"MissingArgument",option);
628 method=ParseCommandOption(MagickPixelIntensityOptions,MagickFalse,
631 ThrowIdentifyException(OptionError,
"UnrecognizedIntensityMethod",
635 if (LocaleCompare(
"green-primary",option+1) == 0)
640 if (i == (ssize_t) argc)
641 ThrowIdentifyException(OptionError,
"MissingArgument",option);
642 if (IsGeometry(argv[i]) == MagickFalse)
643 ThrowIdentifyInvalidArgumentException(option,argv[i]);
646 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
650 if ((LocaleCompare(
"help",option+1) == 0) ||
651 (LocaleCompare(
"-help",option+1) == 0))
654 return(IdentifyUsage());
656 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
660 if (LocaleCompare(
"interlace",option+1) == 0)
668 if (i == (ssize_t) argc)
669 ThrowIdentifyException(OptionError,
"MissingArgument",option);
670 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
673 ThrowIdentifyException(OptionError,
"UnrecognizedInterlaceType",
677 if (LocaleCompare(
"interpolate",option+1) == 0)
685 if (i == (ssize_t) argc)
686 ThrowIdentifyException(OptionError,
"MissingArgument",option);
687 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
690 ThrowIdentifyException(OptionError,
691 "UnrecognizedInterpolateMethod",argv[i]);
694 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
698 if (LocaleCompare(
"limit",option+1) == 0)
712 if (i == (ssize_t) argc)
713 ThrowIdentifyException(OptionError,
"MissingArgument",option);
714 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
717 ThrowIdentifyException(OptionError,
"UnrecognizedResourceType",
720 if (i == (ssize_t) argc)
721 ThrowIdentifyException(OptionError,
"MissingArgument",option);
722 value=StringToDouble(argv[i],&p);
724 if ((p == argv[i]) && (LocaleCompare(
"unlimited",argv[i]) != 0))
725 ThrowIdentifyInvalidArgumentException(option,argv[i]);
728 if (LocaleCompare(
"list",option+1) == 0)
736 if (i == (ssize_t) argc)
737 ThrowIdentifyException(OptionError,
"MissingArgument",option);
738 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
740 ThrowIdentifyException(OptionError,
"UnrecognizedListType",
742 status=MogrifyImageInfo(image_info,(
int) (i-j+1),(
const char **)
745 return(status == 0 ? MagickFalse : MagickTrue);
747 if (LocaleCompare(
"log",option+1) == 0)
752 if ((i == (ssize_t) argc) ||
753 (strchr(argv[i],
'%') == (
char *) NULL))
754 ThrowIdentifyException(OptionError,
"MissingArgument",option);
757 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
761 if (LocaleCompare(
"mask",option+1) == 0)
766 if (i == (ssize_t) argc)
767 ThrowIdentifyException(OptionError,
"MissingArgument",option);
770 if (LocaleCompare(
"matte",option+1) == 0)
772 if (LocaleCompare(
"moments",option+1) == 0)
774 if (LocaleCompare(
"monitor",option+1) == 0)
776 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
780 if (LocaleCompare(
"negate",option+1) == 0)
782 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
786 if (LocaleCompare(
"ping",option+1) == 0)
788 image_info->ping=MagickTrue;
791 if (LocaleCompare(
"precision",option+1) == 0)
796 if (i == (ssize_t) argc)
797 ThrowIdentifyException(OptionError,
"MissingArgument",option);
798 if (IsGeometry(argv[i]) == MagickFalse)
799 ThrowIdentifyInvalidArgumentException(option,argv[i]);
802 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
806 if (LocaleCompare(
"quiet",option+1) == 0)
808 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
812 if (LocaleCompare(
"regard-warnings",option+1) == 0)
814 if ((LocaleNCompare(
"respect-parentheses",option+1,17) == 0) ||
815 (LocaleNCompare(
"respect-parenthesis",option+1,17) == 0))
817 respect_parentheses=(*option ==
'-') ? MagickTrue : MagickFalse;
820 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
824 if (LocaleCompare(
"sampling-factor",option+1) == 0)
829 if (i == (ssize_t) argc)
830 ThrowIdentifyException(OptionError,
"MissingArgument",option);
831 if (IsGeometry(argv[i]) == MagickFalse)
832 ThrowIdentifyInvalidArgumentException(option,argv[i]);
835 if (LocaleCompare(
"seed",option+1) == 0)
840 if (i == (ssize_t) argc)
841 ThrowIdentifyException(OptionError,
"MissingArgument",option);
842 if (IsGeometry(argv[i]) == MagickFalse)
843 ThrowIdentifyInvalidArgumentException(option,argv[i]);
846 if (LocaleCompare(
"set",option+1) == 0)
849 if (i == (ssize_t) argc)
850 ThrowIdentifyException(OptionError,
"MissingArgument",option);
854 if (i == (ssize_t) argc)
855 ThrowIdentifyException(OptionError,
"MissingArgument",option);
858 if (LocaleCompare(
"size",option+1) == 0)
863 if (i == (ssize_t) argc)
864 ThrowIdentifyException(OptionError,
"MissingArgument",option);
865 if (IsGeometry(argv[i]) == MagickFalse)
866 ThrowIdentifyInvalidArgumentException(option,argv[i]);
869 if (LocaleCompare(
"strip",option+1) == 0)
871 if (LocaleCompare(
"support",option+1) == 0)
876 if (i == (ssize_t) argc)
877 ThrowIdentifyException(OptionError,
"MissingArgument",option);
878 if (IsGeometry(argv[i]) == MagickFalse)
879 ThrowIdentifyInvalidArgumentException(option,argv[i]);
882 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
886 if (LocaleCompare(
"unique",option+1) == 0)
888 if (LocaleCompare(
"units",option+1) == 0)
896 if (i == (ssize_t) argc)
897 ThrowIdentifyException(OptionError,
"MissingArgument",option);
898 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
901 ThrowIdentifyException(OptionError,
"UnrecognizedUnitsType",
905 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
909 if (LocaleCompare(
"verbose",option+1) == 0)
911 if (LocaleCompare(
"virtual-pixel",option+1) == 0)
919 if (i == (ssize_t) argc)
920 ThrowIdentifyException(OptionError,
"MissingArgument",option);
921 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
924 ThrowIdentifyException(OptionError,
925 "UnrecognizedVirtualPixelMethod",argv[i]);
928 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
933 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
935 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
936 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
937 if (fire != MagickFalse)
938 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
941 ThrowIdentifyException(OptionError,
"UnbalancedParenthesis",argv[i]);
942 if (i != (ssize_t) argc)
943 ThrowIdentifyException(OptionError,
"MissingAnImageFilename",argv[i]);
945 return(status != 0 ? MagickTrue : MagickFalse);