50 #include "wand/studio.h"
51 #include "wand/MagickWand.h"
52 #include "wand/mogrify-private.h"
53 #include "magick/string-private.h"
93 static 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");
176 WandExport 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);
248 return(IdentifyUsage());
254 option=(
char *) NULL;
256 respect_parenthesis=MagickFalse;
261 ReadCommandlLine(argc,&argv);
262 status=ExpandFilenames(&argc,&argv);
263 if (status == MagickFalse)
264 ThrowIdentifyException(ResourceLimitError,
"MemoryAllocationFailed",
265 GetExceptionMessage(errno));
266 image_info->ping=MagickTrue;
267 for (i=1; i < (ssize_t) argc; i++)
270 if (LocaleCompare(option,
"(") == 0)
272 FireImageStack(MagickFalse,MagickTrue,pend);
273 if (k == MaxImageStackDepth)
274 ThrowIdentifyException(OptionError,
"ParenthesisNestedTooDeeply",
279 if (LocaleCompare(option,
")") == 0)
281 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
283 ThrowIdentifyException(OptionError,
"UnableToParseExpression",option);
287 if (IsCommandOption(option) == MagickFalse)
301 FireImageStack(MagickFalse,MagickFalse,pend);
302 identify_info=CloneImageInfo(image_info);
303 identify_info->verbose=MagickFalse;
305 if ((LocaleCompare(filename,
"--") == 0) && (i < (ssize_t) (argc-1)))
307 (void) SetImageOption(image_info,
"filename",filename);
308 (void) CopyMagickString(identify_info->filename,filename,MaxTextExtent);
309 if (identify_info->ping != MagickFalse)
310 images=PingImages(identify_info,exception);
312 images=ReadImages(identify_info,exception);
313 identify_info=DestroyImageInfo(identify_info);
314 status&=(images != (Image *) NULL) &&
315 (exception->severity < ErrorException);
316 if (images == (Image *) NULL)
318 AppendImageStack(images);
319 FinalizeImageSettings(image_info,image,MagickFalse);
321 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
323 if (image->scene == 0)
324 image->scene=count++;
325 if (format == (
char *) NULL)
327 (void) IdentifyImage(image,stdout,image_info->verbose);
330 if (metadata != (
char **) NULL)
335 text=InterpretImageProperties(image_info,image,format);
336 InheritException(exception,&image->exception);
337 if (text == (
char *) NULL)
338 ThrowIdentifyException(ResourceLimitError,
339 "MemoryAllocationFailed",GetExceptionMessage(errno));
340 (void) ConcatenateString(&(*metadata),text);
341 text=DestroyString(text);
344 RemoveAllImageStack();
347 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
348 image_info->ping=MagickFalse;
353 if (LocaleCompare(
"alpha",option+1) == 0)
361 if (i == (ssize_t) argc)
362 ThrowIdentifyException(OptionError,
"MissingArgument",option);
363 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
365 ThrowIdentifyException(OptionError,
"UnrecognizedAlphaChannelType",
369 if (LocaleCompare(
"antialias",option+1) == 0)
371 if (LocaleCompare(
"authenticate",option+1) == 0)
376 if (i == (ssize_t) argc)
377 ThrowIdentifyException(OptionError,
"MissingArgument",option);
380 if (LocaleCompare(
"auto-orient",option+1) == 0)
382 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
386 if (LocaleCompare(
"cache",option+1) == 0)
391 if (i == (ssize_t) argc)
392 ThrowIdentifyException(OptionError,
"MissingArgument",option);
393 if (IsGeometry(argv[i]) == MagickFalse)
394 ThrowIdentifyInvalidArgumentException(option,argv[i]);
397 if (LocaleCompare(
"channel",option+1) == 0)
405 if (i == (ssize_t) argc)
406 ThrowIdentifyException(OptionError,
"MissingArgument",option);
407 channel=ParseChannelOption(argv[i]);
409 ThrowIdentifyException(OptionError,
"UnrecognizedChannelType",
413 if (LocaleCompare(
"clip",option+1) == 0)
415 if (LocaleCompare(
"clip-mask",option+1) == 0)
420 if (i == (ssize_t) argc)
421 ThrowIdentifyException(OptionError,
"MissingArgument",option);
424 if (LocaleCompare(
"clip-path",option+1) == 0)
427 if (i == (ssize_t) argc)
428 ThrowIdentifyException(OptionError,
"MissingArgument",option);
431 if (LocaleCompare(
"colorspace",option+1) == 0)
439 if (i == (ssize_t) argc)
440 ThrowIdentifyException(OptionError,
"MissingArgument",option);
441 colorspace=ParseCommandOption(MagickColorspaceOptions,
442 MagickFalse,argv[i]);
444 ThrowIdentifyException(OptionError,
"UnrecognizedColorspace",
448 if (LocaleCompare(
"crop",option+1) == 0)
453 if (i == (ssize_t) argc)
454 ThrowIdentifyException(OptionError,
"MissingArgument",option);
455 if (IsGeometry(argv[i]) == MagickFalse)
456 ThrowIdentifyInvalidArgumentException(option,argv[i]);
459 if (LocaleCompare(
"concurrent",option+1) == 0)
461 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
465 if (LocaleCompare(
"debug",option+1) == 0)
473 if (i == (ssize_t) argc)
474 ThrowIdentifyException(OptionError,
"MissingArgument",option);
475 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
477 ThrowIdentifyException(OptionError,
"UnrecognizedEventType",
479 (void) SetLogEventMask(argv[i]);
482 if (LocaleCompare(
"define",option+1) == 0)
485 if (i == (ssize_t) argc)
486 ThrowIdentifyException(OptionError,
"MissingArgument",option);
492 define=GetImageOption(image_info,argv[i]);
493 if (define == (
const char *) NULL)
494 ThrowIdentifyException(OptionError,
"NoSuchOption",argv[i]);
499 if (LocaleCompare(
"density",option+1) == 0)
504 if (i == (ssize_t) argc)
505 ThrowIdentifyException(OptionError,
"MissingArgument",option);
506 if (IsGeometry(argv[i]) == MagickFalse)
507 ThrowIdentifyInvalidArgumentException(option,argv[i]);
510 if (LocaleCompare(
"depth",option+1) == 0)
515 if (i == (ssize_t) argc)
516 ThrowIdentifyException(OptionError,
"MissingArgument",option);
517 if (IsGeometry(argv[i]) == MagickFalse)
518 ThrowIdentifyInvalidArgumentException(option,argv[i]);
521 if (LocaleCompare(
"duration",option+1) == 0)
526 if (i == (ssize_t) argc)
527 ThrowIdentifyException(OptionError,
"MissingArgument",option);
528 if (IsGeometry(argv[i]) == MagickFalse)
529 ThrowIdentifyInvalidArgumentException(option,argv[i]);
532 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
536 if (LocaleCompare(
"endian",option+1) == 0)
544 if (i == (ssize_t) argc)
545 ThrowIdentifyException(OptionError,
"MissingArgument",option);
546 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,
549 ThrowIdentifyException(OptionError,
"UnrecognizedEndianType",
553 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
557 if (LocaleCompare(
"features",option+1) == 0)
562 if (i == (ssize_t) argc)
563 ThrowIdentifyException(OptionError,
"MissingArgument",option);
564 if (IsGeometry(argv[i]) == MagickFalse)
565 ThrowIdentifyInvalidArgumentException(option,argv[i]);
568 if (LocaleCompare(
"format",option+1) == 0)
570 format=(
char *) NULL;
574 if (i == (ssize_t) argc)
575 ThrowIdentifyException(OptionError,
"MissingArgument",option);
579 if (LocaleCompare(
"fuzz",option+1) == 0)
584 if (i == (ssize_t) argc)
585 ThrowIdentifyException(OptionError,
"MissingArgument",option);
586 if (IsGeometry(argv[i]) == MagickFalse)
587 ThrowIdentifyInvalidArgumentException(option,argv[i]);
590 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
594 if (LocaleCompare(
"gamma",option+1) == 0)
597 if (i == (ssize_t) argc)
598 ThrowIdentifyException(OptionError,
"MissingArgument",option);
599 if (IsGeometry(argv[i]) == MagickFalse)
600 ThrowIdentifyInvalidArgumentException(option,argv[i]);
603 if (LocaleCompare(
"grayscale",option+1) == 0)
611 if (i == (ssize_t) argc)
612 ThrowIdentifyException(OptionError,
"MissingArgument",option);
613 method=ParseCommandOption(MagickPixelIntensityOptions,MagickFalse,
616 ThrowIdentifyException(OptionError,
"UnrecognizedIntensityMethod",
620 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
624 if ((LocaleCompare(
"help",option+1) == 0) ||
625 (LocaleCompare(
"-help",option+1) == 0))
628 return(IdentifyUsage());
630 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
634 if (LocaleCompare(
"interlace",option+1) == 0)
642 if (i == (ssize_t) argc)
643 ThrowIdentifyException(OptionError,
"MissingArgument",option);
644 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
647 ThrowIdentifyException(OptionError,
"UnrecognizedInterlaceType",
651 if (LocaleCompare(
"interpolate",option+1) == 0)
659 if (i == (ssize_t) argc)
660 ThrowIdentifyException(OptionError,
"MissingArgument",option);
661 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
664 ThrowIdentifyException(OptionError,
665 "UnrecognizedInterpolateMethod",argv[i]);
668 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
672 if (LocaleCompare(
"limit",option+1) == 0)
686 if (i == (ssize_t) argc)
687 ThrowIdentifyException(OptionError,
"MissingArgument",option);
688 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
691 ThrowIdentifyException(OptionError,
"UnrecognizedResourceType",
694 if (i == (ssize_t) argc)
695 ThrowIdentifyException(OptionError,
"MissingArgument",option);
696 value=StringToDouble(argv[i],&p);
698 if ((p == argv[i]) && (LocaleCompare(
"unlimited",argv[i]) != 0))
699 ThrowIdentifyInvalidArgumentException(option,argv[i]);
702 if (LocaleCompare(
"list",option+1) == 0)
710 if (i == (ssize_t) argc)
711 ThrowIdentifyException(OptionError,
"MissingArgument",option);
712 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
714 ThrowIdentifyException(OptionError,
"UnrecognizedListType",
716 status=MogrifyImageInfo(image_info,(
int) (i-j+1),(
const char **)
719 return(status == 0 ? MagickFalse : MagickTrue);
721 if (LocaleCompare(
"log",option+1) == 0)
726 if ((i == (ssize_t) argc) ||
727 (strchr(argv[i],
'%') == (
char *) NULL))
728 ThrowIdentifyException(OptionError,
"MissingArgument",option);
731 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
735 if (LocaleCompare(
"mask",option+1) == 0)
740 if (i == (ssize_t) argc)
741 ThrowIdentifyException(OptionError,
"MissingArgument",option);
744 if (LocaleCompare(
"matte",option+1) == 0)
746 if (LocaleCompare(
"moments",option+1) == 0)
748 if (LocaleCompare(
"monitor",option+1) == 0)
750 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
754 if (LocaleCompare(
"negate",option+1) == 0)
756 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
760 if (LocaleCompare(
"ping",option+1) == 0)
762 image_info->ping=MagickTrue;
765 if (LocaleCompare(
"precision",option+1) == 0)
770 if (i == (ssize_t) argc)
771 ThrowIdentifyException(OptionError,
"MissingArgument",option);
772 if (IsGeometry(argv[i]) == MagickFalse)
773 ThrowIdentifyInvalidArgumentException(option,argv[i]);
776 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
780 if (LocaleCompare(
"quiet",option+1) == 0)
782 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
786 if (LocaleCompare(
"regard-warnings",option+1) == 0)
788 if (LocaleNCompare(
"respect-parentheses",option+1,17) == 0)
790 respect_parenthesis=(*option ==
'-') ? MagickTrue : MagickFalse;
793 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
797 if (LocaleCompare(
"sampling-factor",option+1) == 0)
802 if (i == (ssize_t) argc)
803 ThrowIdentifyException(OptionError,
"MissingArgument",option);
804 if (IsGeometry(argv[i]) == MagickFalse)
805 ThrowIdentifyInvalidArgumentException(option,argv[i]);
808 if (LocaleCompare(
"seed",option+1) == 0)
813 if (i == (ssize_t) argc)
814 ThrowIdentifyException(OptionError,
"MissingArgument",option);
815 if (IsGeometry(argv[i]) == MagickFalse)
816 ThrowIdentifyInvalidArgumentException(option,argv[i]);
819 if (LocaleCompare(
"set",option+1) == 0)
822 if (i == (ssize_t) argc)
823 ThrowIdentifyException(OptionError,
"MissingArgument",option);
827 if (i == (ssize_t) argc)
828 ThrowIdentifyException(OptionError,
"MissingArgument",option);
831 if (LocaleCompare(
"size",option+1) == 0)
836 if (i == (ssize_t) argc)
837 ThrowIdentifyException(OptionError,
"MissingArgument",option);
838 if (IsGeometry(argv[i]) == MagickFalse)
839 ThrowIdentifyInvalidArgumentException(option,argv[i]);
842 if (LocaleCompare(
"strip",option+1) == 0)
844 if (LocaleCompare(
"support",option+1) == 0)
849 if (i == (ssize_t) argc)
850 ThrowIdentifyException(OptionError,
"MissingArgument",option);
851 if (IsGeometry(argv[i]) == MagickFalse)
852 ThrowIdentifyInvalidArgumentException(option,argv[i]);
855 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
859 if (LocaleCompare(
"unique",option+1) == 0)
861 if (LocaleCompare(
"units",option+1) == 0)
869 if (i == (ssize_t) argc)
870 ThrowIdentifyException(OptionError,
"MissingArgument",option);
871 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
874 ThrowIdentifyException(OptionError,
"UnrecognizedUnitsType",
878 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
882 if (LocaleCompare(
"verbose",option+1) == 0)
884 if (LocaleCompare(
"virtual-pixel",option+1) == 0)
892 if (i == (ssize_t) argc)
893 ThrowIdentifyException(OptionError,
"MissingArgument",option);
894 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
897 ThrowIdentifyException(OptionError,
898 "UnrecognizedVirtualPixelMethod",argv[i]);
901 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
906 ThrowIdentifyException(OptionError,
"UnrecognizedOption",option)
908 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
909 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
910 if (fire != MagickFalse)
911 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
914 ThrowIdentifyException(OptionError,
"UnbalancedParenthesis",argv[i]);
915 if (i != (ssize_t) argc)
916 ThrowIdentifyException(OptionError,
"MissingAnImageFilename",argv[i]);
918 return(status != 0 ? MagickTrue : MagickFalse);