50#include "wand/studio.h"
51#include "wand/MagickWand.h"
52#include "wand/mogrify-private.h"
53#include "magick/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 " -grayscale method convert image to grayscale\n"
105 " -negate replace every pixel with its complementary color",
107 " -alpha option on, activate, off, deactivate, set, opaque, copy\n"
108 " transparent, extract, background, or shape\n"
109 " -antialias remove pixel-aliasing\n"
110 " -authenticate password\n"
111 " decipher image with this password\n"
112 " -channel type apply option to select image channels\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 " -list type Color, Configure, Delegate, Format, Magic, Module,\n"
132 " Resource, or Type\n"
133 " -mask filename associate a mask with the image\n"
134 " -matte store matte channel if the image has one\n"
135 " -moments report image moments\n"
136 " -format \"string\" output formatted image characteristics\n"
137 " -monitor monitor progress\n"
138 " -ping efficiently determine image attributes\n"
139 " -precision value maximum number of significant digits to print\n"
140 " -quiet suppress all warning messages\n"
141 " -regard-warnings pay attention to warning messages\n"
142 " -respect-parentheses settings remain in effect until parenthesis boundary\n"
143 " -sampling-factor geometry\n"
144 " horizontal and vertical sampling factor\n"
145 " -seed value seed a new sequence of pseudo-random numbers\n"
146 " -set attribute value set an image attribute\n"
147 " -size geometry width and height of image\n"
148 " -strip strip image of all profiles and comments\n"
149 " -unique display the number of unique colors in the image\n"
150 " -units type the units of image resolution\n"
151 " -verbose print detailed information about the image\n"
152 " -virtual-pixel method\n"
153 " virtual pixel access method";
155 ListMagickVersion(stdout);
156 (void) printf(
"Usage: %s [options ...] file [ [options ...] "
157 "file ... ]\n",GetClientName());
158 (void) printf(
"\nImage Settings:\n");
159 (void) puts(settings);
160 (void) printf(
"\nImage Operators:\n");
161 (void) puts(operators);
162 (void) printf(
"\nMiscellaneous Options:\n");
163 (void) puts(miscellaneous);
165 "\nBy default, the image format of `file' is determined by its magic\n");
167 "number. To specify a particular image format, precede the filename\n");
169 "with an image format name and a colon (i.e. ps:image) or specify the\n");
171 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
172 (void) printf(
"'-' for standard input or output.\n");
176WandExport MagickBooleanType IdentifyImageCommand(ImageInfo *image_info,
177 int argc,
char **argv,
char **metadata,ExceptionInfo *exception)
179#define DestroyIdentify() \
181 DestroyImageStack(); \
182 for (i=0; i < (ssize_t) argc; i++) \
183 argv[i]=DestroyString(argv[i]); \
184 argv=(char **) RelinquishMagickMemory(argv); \
186#define ThrowIdentifyException(asperity,tag,option) \
188 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
191 return(MagickFalse); \
193#define ThrowIdentifyInvalidArgumentException(option,argument) \
195 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
196 "InvalidArgument","`%s': %s",option,argument); \
198 return(MagickFalse); \
209 image_stack[MaxImageStackDepth+1];
232 assert(image_info != (ImageInfo *) NULL);
233 assert(image_info->signature == MagickCoreSignature);
234 assert(exception != (ExceptionInfo *) NULL);
235 if (IsEventLogging() != MagickFalse)
236 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
240 if ((LocaleCompare(
"version",option+1) == 0) ||
241 (LocaleCompare(
"-version",option+1) == 0))
243 ListMagickVersion(stdout);
249 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
250 "MissingArgument",
"%s",
"");
251 (void) IdentifyUsage();
259 option=(
char *) NULL;
261 respect_parenthesis=MagickFalse;
266 ReadCommandlLine(argc,&argv);
267 status=ExpandFilenames(&argc,&argv);
268 if (status == MagickFalse)
269 ThrowIdentifyException(ResourceLimitError,
"MemoryAllocationFailed",
270 GetExceptionMessage(errno));
271 image_info->ping=MagickTrue;
272 for (i=1; i < (ssize_t) argc; i++)
275 if (LocaleCompare(option,
"(") == 0)
277 FireImageStack(MagickFalse,MagickTrue,pend);
278 if (k == MaxImageStackDepth)
279 ThrowIdentifyException(OptionError,
"ParenthesisNestedTooDeeply",
284 if (LocaleCompare(option,
")") == 0)
286 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
288 ThrowIdentifyException(OptionError,
"UnableToParseExpression",option);
292 if (IsCommandOption(option) == MagickFalse)
306 FireImageStack(MagickFalse,MagickFalse,pend);
307 identify_info=CloneImageInfo(image_info);
308 identify_info->verbose=MagickFalse;
310 if ((LocaleCompare(filename,
"--") == 0) && (i < (ssize_t) (argc-1)))
312 (void) SetImageOption(image_info,
"filename",filename);
313 (void) CopyMagickString(identify_info->filename,filename,MaxTextExtent);
314 if (identify_info->ping != MagickFalse)
315 images=PingImages(identify_info,exception);
317 images=ReadImages(identify_info,exception);
318 identify_info=DestroyImageInfo(identify_info);
319 status&=(images != (Image *) NULL) &&
320 (exception->severity < ErrorException);
321 if (images == (Image *) NULL)
323 AppendImageStack(images);
324 FinalizeImageSettings(image_info,image,MagickFalse);
326 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
328 if (image->scene == 0)
329 image->scene=count++;
330 if (format == (
char *) NULL)
332 (void) IdentifyImage(image,stdout,image_info->verbose);
335 if (metadata != (
char **) NULL)
340 text=InterpretImageProperties(image_info,image,format);
341 InheritException(exception,&image->exception);
342 if (text == (
char *) NULL)
343 ThrowIdentifyException(ResourceLimitError,
344 "MemoryAllocationFailed",GetExceptionMessage(errno));
345 (void) ConcatenateString(&(*metadata),text);
346 text=DestroyString(text);
349 RemoveAllImageStack();
352 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
353 image_info->ping=MagickFalse;
358 if (LocaleCompare(
"alpha",option+1) == 0)
366 if (i == (ssize_t) argc)
367 ThrowIdentifyException(OptionError,
"MissingArgument",option);
368 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
370 ThrowIdentifyException(OptionError,
"UnrecognizedAlphaChannelType",
374 if (LocaleCompare(
"antialias",option+1) == 0)
376 if (LocaleCompare(
"authenticate",option+1) == 0)
381 if (i == (ssize_t) argc)
382 ThrowIdentifyException(OptionError,
"MissingArgument",option);
385 if (LocaleCompare(
"auto-orient",option+1) == 0)
387 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
391 if (LocaleCompare(
"cache",option+1) == 0)
396 if (i == (ssize_t) argc)
397 ThrowIdentifyException(OptionError,
"MissingArgument",option);
398 if (IsGeometry(argv[i]) == MagickFalse)
399 ThrowIdentifyInvalidArgumentException(option,argv[i]);
402 if (LocaleCompare(
"channel",option+1) == 0)
410 if (i == (ssize_t) argc)
411 ThrowIdentifyException(OptionError,
"MissingArgument",option);
412 channel=ParseChannelOption(argv[i]);
414 ThrowIdentifyException(OptionError,
"UnrecognizedChannelType",
418 if (LocaleCompare(
"clip",option+1) == 0)
420 if (LocaleCompare(
"clip-mask",option+1) == 0)
425 if (i == (ssize_t) argc)
426 ThrowIdentifyException(OptionError,
"MissingArgument",option);
429 if (LocaleCompare(
"clip-path",option+1) == 0)
432 if (i == (ssize_t) argc)
433 ThrowIdentifyException(OptionError,
"MissingArgument",option);
436 if (LocaleCompare(
"colorspace",option+1) == 0)
444 if (i == (ssize_t) argc)
445 ThrowIdentifyException(OptionError,
"MissingArgument",option);
446 colorspace=ParseCommandOption(MagickColorspaceOptions,
447 MagickFalse,argv[i]);
449 ThrowIdentifyException(OptionError,
"UnrecognizedColorspace",
453 if (LocaleCompare(
"crop",option+1) == 0)
458 if (i == (ssize_t) argc)
459 ThrowIdentifyException(OptionError,
"MissingArgument",option);
460 if (IsGeometry(argv[i]) == MagickFalse)
461 ThrowIdentifyInvalidArgumentException(option,argv[i]);
464 if (LocaleCompare(
"concurrent",option+1) == 0)
466 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
470 if (LocaleCompare(
"debug",option+1) == 0)
478 if (i == (ssize_t) argc)
479 ThrowIdentifyException(OptionError,
"MissingArgument",option);
480 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
482 ThrowIdentifyException(OptionError,
"UnrecognizedEventType",
484 (void) SetLogEventMask(argv[i]);
487 if (LocaleCompare(
"define",option+1) == 0)
490 if (i == (ssize_t) argc)
491 ThrowIdentifyException(OptionError,
"MissingArgument",option);
497 define=GetImageOption(image_info,argv[i]);
498 if (define == (
const char *) NULL)
499 ThrowIdentifyException(OptionError,
"NoSuchOption",argv[i]);
502 if (LocaleNCompare(
"identify:locate",argv[i],15) == 0)
503 image_info->ping=MagickFalse;
506 if (LocaleCompare(
"density",option+1) == 0)
511 if (i == (ssize_t) argc)
512 ThrowIdentifyException(OptionError,
"MissingArgument",option);
513 if (IsGeometry(argv[i]) == MagickFalse)
514 ThrowIdentifyInvalidArgumentException(option,argv[i]);
517 if (LocaleCompare(
"depth",option+1) == 0)
522 if (i == (ssize_t) argc)
523 ThrowIdentifyException(OptionError,
"MissingArgument",option);
524 if (IsGeometry(argv[i]) == MagickFalse)
525 ThrowIdentifyInvalidArgumentException(option,argv[i]);
528 if (LocaleCompare(
"duration",option+1) == 0)
533 if (i == (ssize_t) argc)
534 ThrowIdentifyException(OptionError,
"MissingArgument",option);
535 if (IsGeometry(argv[i]) == MagickFalse)
536 ThrowIdentifyInvalidArgumentException(option,argv[i]);
539 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
543 if (LocaleCompare(
"endian",option+1) == 0)
551 if (i == (ssize_t) argc)
552 ThrowIdentifyException(OptionError,
"MissingArgument",option);
553 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,
556 ThrowIdentifyException(OptionError,
"UnrecognizedEndianType",
560 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
564 if (LocaleCompare(
"features",option+1) == 0)
569 if (i == (ssize_t) argc)
570 ThrowIdentifyException(OptionError,
"MissingArgument",option);
571 if (IsGeometry(argv[i]) == MagickFalse)
572 ThrowIdentifyInvalidArgumentException(option,argv[i]);
575 if (LocaleCompare(
"format",option+1) == 0)
577 format=(
char *) NULL;
581 if (i == (ssize_t) argc)
582 ThrowIdentifyException(OptionError,
"MissingArgument",option);
584 image_info->ping=MagickFalse;
587 if (LocaleCompare(
"fuzz",option+1) == 0)
592 if (i == (ssize_t) argc)
593 ThrowIdentifyException(OptionError,
"MissingArgument",option);
594 if (IsGeometry(argv[i]) == MagickFalse)
595 ThrowIdentifyInvalidArgumentException(option,argv[i]);
598 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
602 if (LocaleCompare(
"gamma",option+1) == 0)
605 if (i == (ssize_t) argc)
606 ThrowIdentifyException(OptionError,
"MissingArgument",option);
607 if (IsGeometry(argv[i]) == MagickFalse)
608 ThrowIdentifyInvalidArgumentException(option,argv[i]);
611 if (LocaleCompare(
"grayscale",option+1) == 0)
619 if (i == (ssize_t) argc)
620 ThrowIdentifyException(OptionError,
"MissingArgument",option);
621 method=ParseCommandOption(MagickPixelIntensityOptions,MagickFalse,
624 ThrowIdentifyException(OptionError,
"UnrecognizedIntensityMethod",
628 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
632 if ((LocaleCompare(
"help",option+1) == 0) ||
633 (LocaleCompare(
"-help",option+1) == 0))
636 return(IdentifyUsage());
638 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
642 if (LocaleCompare(
"interlace",option+1) == 0)
650 if (i == (ssize_t) argc)
651 ThrowIdentifyException(OptionError,
"MissingArgument",option);
652 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
655 ThrowIdentifyException(OptionError,
"UnrecognizedInterlaceType",
659 if (LocaleCompare(
"interpolate",option+1) == 0)
667 if (i == (ssize_t) argc)
668 ThrowIdentifyException(OptionError,
"MissingArgument",option);
669 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
672 ThrowIdentifyException(OptionError,
673 "UnrecognizedInterpolateMethod",argv[i]);
676 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
680 if (LocaleCompare(
"limit",option+1) == 0)
694 if (i == (ssize_t) argc)
695 ThrowIdentifyException(OptionError,
"MissingArgument",option);
696 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
699 ThrowIdentifyException(OptionError,
"UnrecognizedResourceType",
702 if (i == (ssize_t) argc)
703 ThrowIdentifyException(OptionError,
"MissingArgument",option);
704 value=StringToDouble(argv[i],&p);
706 if ((p == argv[i]) && (LocaleCompare(
"unlimited",argv[i]) != 0))
707 ThrowIdentifyInvalidArgumentException(option,argv[i]);
710 if (LocaleCompare(
"list",option+1) == 0)
718 if (i == (ssize_t) argc)
719 ThrowIdentifyException(OptionError,
"MissingArgument",option);
720 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
722 ThrowIdentifyException(OptionError,
"UnrecognizedListType",
724 status=MogrifyImageInfo(image_info,(
int) (i-j+1),(
const char **)
727 return(status == 0 ? MagickFalse : MagickTrue);
729 if (LocaleCompare(
"log",option+1) == 0)
734 if ((i == (ssize_t) argc) ||
735 (strchr(argv[i],
'%') == (
char *) NULL))
736 ThrowIdentifyException(OptionError,
"MissingArgument",option);
739 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
743 if (LocaleCompare(
"mask",option+1) == 0)
748 if (i == (ssize_t) argc)
749 ThrowIdentifyException(OptionError,
"MissingArgument",option);
752 if (LocaleCompare(
"matte",option+1) == 0)
754 if (LocaleCompare(
"moments",option+1) == 0)
756 if (LocaleCompare(
"monitor",option+1) == 0)
758 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
762 if (LocaleCompare(
"negate",option+1) == 0)
764 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
768 if (LocaleCompare(
"ping",option+1) == 0)
770 image_info->ping=MagickTrue;
773 if (LocaleCompare(
"precision",option+1) == 0)
778 if (i == (ssize_t) argc)
779 ThrowIdentifyException(OptionError,
"MissingArgument",option);
780 if (IsGeometry(argv[i]) == MagickFalse)
781 ThrowIdentifyInvalidArgumentException(option,argv[i]);
784 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
788 if (LocaleCompare(
"quiet",option+1) == 0)
790 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
794 if (LocaleCompare(
"regard-warnings",option+1) == 0)
796 if (LocaleNCompare(
"respect-parentheses",option+1,17) == 0)
798 respect_parenthesis=(*option ==
'-') ? MagickTrue : MagickFalse;
801 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
805 if (LocaleCompare(
"sampling-factor",option+1) == 0)
810 if (i == (ssize_t) argc)
811 ThrowIdentifyException(OptionError,
"MissingArgument",option);
812 if (IsGeometry(argv[i]) == MagickFalse)
813 ThrowIdentifyInvalidArgumentException(option,argv[i]);
816 if (LocaleCompare(
"seed",option+1) == 0)
821 if (i == (ssize_t) argc)
822 ThrowIdentifyException(OptionError,
"MissingArgument",option);
823 if (IsGeometry(argv[i]) == MagickFalse)
824 ThrowIdentifyInvalidArgumentException(option,argv[i]);
827 if (LocaleCompare(
"set",option+1) == 0)
830 if (i == (ssize_t) argc)
831 ThrowIdentifyException(OptionError,
"MissingArgument",option);
835 if (i == (ssize_t) argc)
836 ThrowIdentifyException(OptionError,
"MissingArgument",option);
839 if (LocaleCompare(
"size",option+1) == 0)
844 if (i == (ssize_t) argc)
845 ThrowIdentifyException(OptionError,
"MissingArgument",option);
846 if (IsGeometry(argv[i]) == MagickFalse)
847 ThrowIdentifyInvalidArgumentException(option,argv[i]);
850 if (LocaleCompare(
"strip",option+1) == 0)
852 if (LocaleCompare(
"support",option+1) == 0)
857 if (i == (ssize_t) argc)
858 ThrowIdentifyException(OptionError,
"MissingArgument",option);
859 if (IsGeometry(argv[i]) == MagickFalse)
860 ThrowIdentifyInvalidArgumentException(option,argv[i]);
863 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
867 if (LocaleCompare(
"unique",option+1) == 0)
869 if (LocaleCompare(
"units",option+1) == 0)
877 if (i == (ssize_t) argc)
878 ThrowIdentifyException(OptionError,
"MissingArgument",option);
879 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
882 ThrowIdentifyException(OptionError,
"UnrecognizedUnitsType",
886 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
890 if (LocaleCompare(
"verbose",option+1) == 0)
892 if (LocaleCompare(
"virtual-pixel",option+1) == 0)
900 if (i == (ssize_t) argc)
901 ThrowIdentifyException(OptionError,
"MissingArgument",option);
902 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
905 ThrowIdentifyException(OptionError,
906 "UnrecognizedVirtualPixelMethod",argv[i]);
909 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
914 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
916 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
917 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
918 if (fire != MagickFalse)
919 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
922 ThrowIdentifyException(OptionError,
"UnbalancedParenthesis",argv[i]);
923 if (i != (ssize_t) argc)
924 ThrowIdentifyException(OptionError,
"MissingAnImageFilename",argv[i]);
926 return(status != 0 ? MagickTrue : MagickFalse);