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 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
187 return(MagickFalse); \
189#define ThrowIdentifyInvalidArgumentException(option,argument) \
191 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
192 "InvalidArgument","'%s': %s",option,argument); \
194 return(MagickFalse); \
205 image_stack[MaxImageStackDepth+1];
228 assert(image_info != (ImageInfo *) NULL);
229 assert(image_info->signature == MagickCoreSignature);
230 assert(exception != (ExceptionInfo *) NULL);
231 if (IsEventLogging() != MagickFalse)
232 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
236 if ((LocaleCompare(
"version",option+1) == 0) ||
237 (LocaleCompare(
"-version",option+1) == 0))
239 ListMagickVersion(stdout);
245 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
246 "MissingArgument",
"%s",
"");
247 (void) IdentifyUsage();
255 option=(
char *) NULL;
257 respect_parenthesis=MagickFalse;
262 ReadCommandlLine(argc,&argv);
263 status=ExpandFilenames(&argc,&argv);
264 if (status == MagickFalse)
265 ThrowIdentifyException(ResourceLimitError,
"MemoryAllocationFailed",
266 GetExceptionMessage(errno));
267 image_info->ping=MagickTrue;
268 for (i=1; i < (ssize_t) argc; i++)
271 if (LocaleCompare(option,
"(") == 0)
273 FireImageStack(MagickFalse,MagickTrue,pend);
274 if (k == MaxImageStackDepth)
275 ThrowIdentifyException(OptionError,
"ParenthesisNestedTooDeeply",
280 if (LocaleCompare(option,
")") == 0)
282 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
284 ThrowIdentifyException(OptionError,
"UnableToParseExpression",option);
288 if (IsCommandOption(option) == MagickFalse)
302 FireImageStack(MagickFalse,MagickFalse,pend);
303 identify_info=CloneImageInfo(image_info);
304 identify_info->verbose=MagickFalse;
306 if ((LocaleCompare(filename,
"--") == 0) && (i < (ssize_t) (argc-1)))
308 if (identify_info->ping != MagickFalse)
309 images=PingImages(identify_info,filename,exception);
311 images=ReadImages(identify_info,filename,exception);
312 identify_info=DestroyImageInfo(identify_info);
313 status&=(MagickStatusType) (images != (Image *) NULL) &&
314 (exception->severity < ErrorException);
315 if (images == (Image *) NULL)
317 AppendImageStack(images);
318 FinalizeImageSettings(image_info,image,MagickFalse);
320 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
322 if (image->scene == 0)
323 image->scene=count++;
324 if (format == (
char *) NULL)
326 (void) IdentifyImage(image,stdout,image_info->verbose,exception);
329 if (metadata != (
char **) NULL)
334 text=InterpretImageProperties(image_info,image,format,exception);
335 if (text == (
char *) NULL)
336 ThrowIdentifyException(ResourceLimitError,
337 "MemoryAllocationFailed",GetExceptionMessage(errno));
338 (void) ConcatenateString(&(*metadata),text);
339 text=DestroyString(text);
342 RemoveAllImageStack();
345 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
346 image_info->ping=MagickFalse;
351 if (LocaleCompare(
"alpha",option+1) == 0)
359 if (i == (ssize_t) argc)
360 ThrowIdentifyException(OptionError,
"MissingArgument",option);
361 type=ParseCommandOption(MagickAlphaChannelOptions,MagickFalse,
364 ThrowIdentifyException(OptionError,
365 "UnrecognizedAlphaChannelOption",argv[i]);
368 if (LocaleCompare(
"antialias",option+1) == 0)
370 if (LocaleCompare(
"authenticate",option+1) == 0)
375 if (i == (ssize_t) argc)
376 ThrowIdentifyException(OptionError,
"MissingArgument",option);
379 if (LocaleCompare(
"auto-orient",option+1) == 0)
381 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
385 if (LocaleCompare(
"cache",option+1) == 0)
390 if (i == (ssize_t) argc)
391 ThrowIdentifyException(OptionError,
"MissingArgument",option);
392 if (IsGeometry(argv[i]) == MagickFalse)
393 ThrowIdentifyInvalidArgumentException(option,argv[i]);
396 if (LocaleCompare(
"channel",option+1) == 0)
404 if (i == (ssize_t) argc)
405 ThrowIdentifyException(OptionError,
"MissingArgument",option);
406 channel=ParseChannelOption(argv[i]);
408 ThrowIdentifyException(OptionError,
"UnrecognizedChannelType",
412 if (LocaleCompare(
"clip",option+1) == 0)
414 if (LocaleCompare(
"clip-mask",option+1) == 0)
419 if (i == (ssize_t) argc)
420 ThrowIdentifyException(OptionError,
"MissingArgument",option);
423 if (LocaleCompare(
"clip-path",option+1) == 0)
426 if (i == (ssize_t) argc)
427 ThrowIdentifyException(OptionError,
"MissingArgument",option);
430 if (LocaleCompare(
"colorspace",option+1) == 0)
438 if (i == (ssize_t) argc)
439 ThrowIdentifyException(OptionError,
"MissingArgument",option);
440 colorspace=ParseCommandOption(MagickColorspaceOptions,
441 MagickFalse,argv[i]);
443 ThrowIdentifyException(OptionError,
"UnrecognizedColorspace",
447 if (LocaleCompare(
"crop",option+1) == 0)
452 if (i == (ssize_t) argc)
453 ThrowIdentifyException(OptionError,
"MissingArgument",option);
454 if (IsGeometry(argv[i]) == MagickFalse)
455 ThrowIdentifyInvalidArgumentException(option,argv[i]);
458 if (LocaleCompare(
"concurrent",option+1) == 0)
460 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
464 if (LocaleCompare(
"debug",option+1) == 0)
472 if (i == (ssize_t) argc)
473 ThrowIdentifyException(OptionError,
"MissingArgument",option);
474 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
476 ThrowIdentifyException(OptionError,
"UnrecognizedEventType",
478 (void) SetLogEventMask(argv[i]);
481 if (LocaleCompare(
"define",option+1) == 0)
484 if (i == (ssize_t) argc)
485 ThrowIdentifyException(OptionError,
"MissingArgument",option);
491 define=GetImageOption(image_info,argv[i]);
492 if (define == (
const char *) NULL)
493 ThrowIdentifyException(OptionError,
"NoSuchOption",argv[i]);
498 if (LocaleCompare(
"density",option+1) == 0)
503 if (i == (ssize_t) argc)
504 ThrowIdentifyException(OptionError,
"MissingArgument",option);
505 if (IsGeometry(argv[i]) == MagickFalse)
506 ThrowIdentifyInvalidArgumentException(option,argv[i]);
509 if (LocaleCompare(
"depth",option+1) == 0)
514 if (i == (ssize_t) argc)
515 ThrowIdentifyException(OptionError,
"MissingArgument",option);
516 if (IsGeometry(argv[i]) == MagickFalse)
517 ThrowIdentifyInvalidArgumentException(option,argv[i]);
520 if (LocaleCompare(
"duration",option+1) == 0)
525 if (i == (ssize_t) argc)
526 ThrowIdentifyException(OptionError,
"MissingArgument",option);
527 if (IsGeometry(argv[i]) == MagickFalse)
528 ThrowIdentifyInvalidArgumentException(option,argv[i]);
531 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
535 if (LocaleCompare(
"endian",option+1) == 0)
543 if (i == (ssize_t) argc)
544 ThrowIdentifyException(OptionError,
"MissingArgument",option);
545 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,
548 ThrowIdentifyException(OptionError,
"UnrecognizedEndianType",
552 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
556 if (LocaleCompare(
"features",option+1) == 0)
561 if (i == (ssize_t) argc)
562 ThrowIdentifyException(OptionError,
"MissingArgument",option);
563 if (IsGeometry(argv[i]) == MagickFalse)
564 ThrowIdentifyInvalidArgumentException(option,argv[i]);
567 if (LocaleCompare(
"format",option+1) == 0)
569 format=(
char *) NULL;
573 if (i == (ssize_t) argc)
574 ThrowIdentifyException(OptionError,
"MissingArgument",option);
578 if (LocaleCompare(
"fuzz",option+1) == 0)
583 if (i == (ssize_t) argc)
584 ThrowIdentifyException(OptionError,
"MissingArgument",option);
585 if (IsGeometry(argv[i]) == MagickFalse)
586 ThrowIdentifyInvalidArgumentException(option,argv[i]);
589 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
593 if (LocaleCompare(
"gamma",option+1) == 0)
596 if (i == (ssize_t) argc)
597 ThrowIdentifyException(OptionError,
"MissingArgument",option);
598 if (IsGeometry(argv[i]) == MagickFalse)
599 ThrowIdentifyInvalidArgumentException(option,argv[i]);
602 if (LocaleCompare(
"grayscale",option+1) == 0)
610 if (i == (ssize_t) argc)
611 ThrowIdentifyException(OptionError,
"MissingArgument",option);
612 method=ParseCommandOption(MagickPixelIntensityOptions,MagickFalse,
615 ThrowIdentifyException(OptionError,
"UnrecognizedIntensityMethod",
619 if (LocaleCompare(
"green-primary",option+1) == 0)
624 if (i == (ssize_t) argc)
625 ThrowIdentifyException(OptionError,
"MissingArgument",option);
626 if (IsGeometry(argv[i]) == MagickFalse)
627 ThrowIdentifyInvalidArgumentException(option,argv[i]);
630 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
634 if ((LocaleCompare(
"help",option+1) == 0) ||
635 (LocaleCompare(
"-help",option+1) == 0))
638 return(IdentifyUsage());
640 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
644 if (LocaleCompare(
"interlace",option+1) == 0)
652 if (i == (ssize_t) argc)
653 ThrowIdentifyException(OptionError,
"MissingArgument",option);
654 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
657 ThrowIdentifyException(OptionError,
"UnrecognizedInterlaceType",
661 if (LocaleCompare(
"interpolate",option+1) == 0)
669 if (i == (ssize_t) argc)
670 ThrowIdentifyException(OptionError,
"MissingArgument",option);
671 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
674 ThrowIdentifyException(OptionError,
675 "UnrecognizedInterpolateMethod",argv[i]);
678 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
682 if (LocaleCompare(
"limit",option+1) == 0)
696 if (i == (ssize_t) argc)
697 ThrowIdentifyException(OptionError,
"MissingArgument",option);
698 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
701 ThrowIdentifyException(OptionError,
"UnrecognizedResourceType",
704 if (i == (ssize_t) argc)
705 ThrowIdentifyException(OptionError,
"MissingArgument",option);
706 value=StringToDouble(argv[i],&p);
708 if ((p == argv[i]) && (LocaleCompare(
"unlimited",argv[i]) != 0))
709 ThrowIdentifyInvalidArgumentException(option,argv[i]);
712 if (LocaleCompare(
"list",option+1) == 0)
720 if (i == (ssize_t) argc)
721 ThrowIdentifyException(OptionError,
"MissingArgument",option);
722 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
724 ThrowIdentifyException(OptionError,
"UnrecognizedListType",
726 status=MogrifyImageInfo(image_info,(
int) (i-j+1),(
const char **)
729 return(status == 0 ? MagickFalse : MagickTrue);
731 if (LocaleCompare(
"log",option+1) == 0)
736 if ((i == (ssize_t) argc) ||
737 (strchr(argv[i],
'%') == (
char *) NULL))
738 ThrowIdentifyException(OptionError,
"MissingArgument",option);
741 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
745 if (LocaleCompare(
"mask",option+1) == 0)
750 if (i == (ssize_t) argc)
751 ThrowIdentifyException(OptionError,
"MissingArgument",option);
754 if (LocaleCompare(
"matte",option+1) == 0)
756 if (LocaleCompare(
"moments",option+1) == 0)
758 if (LocaleCompare(
"monitor",option+1) == 0)
760 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
764 if (LocaleCompare(
"negate",option+1) == 0)
766 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
770 if (LocaleCompare(
"ping",option+1) == 0)
772 image_info->ping=MagickTrue;
775 if (LocaleCompare(
"precision",option+1) == 0)
780 if (i == (ssize_t) argc)
781 ThrowIdentifyException(OptionError,
"MissingArgument",option);
782 if (IsGeometry(argv[i]) == MagickFalse)
783 ThrowIdentifyInvalidArgumentException(option,argv[i]);
786 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
790 if (LocaleCompare(
"quiet",option+1) == 0)
792 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
796 if (LocaleCompare(
"regard-warnings",option+1) == 0)
798 if (LocaleNCompare(
"respect-parentheses",option+1,17) == 0)
800 respect_parenthesis=(*option ==
'-') ? MagickTrue : MagickFalse;
803 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
807 if (LocaleCompare(
"sampling-factor",option+1) == 0)
812 if (i == (ssize_t) argc)
813 ThrowIdentifyException(OptionError,
"MissingArgument",option);
814 if (IsGeometry(argv[i]) == MagickFalse)
815 ThrowIdentifyInvalidArgumentException(option,argv[i]);
818 if (LocaleCompare(
"seed",option+1) == 0)
823 if (i == (ssize_t) argc)
824 ThrowIdentifyException(OptionError,
"MissingArgument",option);
825 if (IsGeometry(argv[i]) == MagickFalse)
826 ThrowIdentifyInvalidArgumentException(option,argv[i]);
829 if (LocaleCompare(
"set",option+1) == 0)
832 if (i == (ssize_t) argc)
833 ThrowIdentifyException(OptionError,
"MissingArgument",option);
837 if (i == (ssize_t) argc)
838 ThrowIdentifyException(OptionError,
"MissingArgument",option);
841 if (LocaleCompare(
"size",option+1) == 0)
846 if (i == (ssize_t) argc)
847 ThrowIdentifyException(OptionError,
"MissingArgument",option);
848 if (IsGeometry(argv[i]) == MagickFalse)
849 ThrowIdentifyInvalidArgumentException(option,argv[i]);
852 if (LocaleCompare(
"strip",option+1) == 0)
854 if (LocaleCompare(
"support",option+1) == 0)
859 if (i == (ssize_t) argc)
860 ThrowIdentifyException(OptionError,
"MissingArgument",option);
861 if (IsGeometry(argv[i]) == MagickFalse)
862 ThrowIdentifyInvalidArgumentException(option,argv[i]);
865 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
869 if (LocaleCompare(
"unique",option+1) == 0)
871 if (LocaleCompare(
"units",option+1) == 0)
879 if (i == (ssize_t) argc)
880 ThrowIdentifyException(OptionError,
"MissingArgument",option);
881 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
884 ThrowIdentifyException(OptionError,
"UnrecognizedUnitsType",
888 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
892 if (LocaleCompare(
"verbose",option+1) == 0)
894 if (LocaleCompare(
"virtual-pixel",option+1) == 0)
902 if (i == (ssize_t) argc)
903 ThrowIdentifyException(OptionError,
"MissingArgument",option);
904 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
907 ThrowIdentifyException(OptionError,
908 "UnrecognizedVirtualPixelMethod",argv[i]);
911 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
916 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
918 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
919 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
920 if (fire != MagickFalse)
921 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
924 ThrowIdentifyException(OptionError,
"UnbalancedParenthesis",argv[i]);
925 if (i != (ssize_t) argc)
926 ThrowIdentifyException(OptionError,
"MissingAnImageFilename",argv[i]);
928 return(status != 0 ? MagickTrue : MagickFalse);