2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % IIIII DDDD EEEEE N N TTTTT IIIII FFFFF Y Y %
7 % I D D E NN N T I F Y Y %
8 % I D D EEE N N N T I FFF Y %
9 % I D D E N NN T I F Y %
10 % IIIII DDDD EEEEE N N T IIIII F Y %
13 % Identify an Image Format and Characteristics. %
20 % Copyright 1999-2013 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 % http://www.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 % The identify program describes the format and characteristics of one or more
37 % image files. It also reports if an image is incomplete or corrupt. The
38 % information returned includes the image number, the file name, the width and
39 % height of the image, whether the image is colormapped or not, the number of
40 % colors in the image, the number of bytes in the image, the format of the
41 % image (JPEG, PNM, etc.), and finally the number of seconds it took to read
42 % and process the image. Many more attributes are available with the verbose
50 #include "MagickWand/studio.h"
51 #include "MagickWand/MagickWand.h"
52 #include "MagickWand/mogrify-private.h"
53 #include "MagickCore/string-private.h"
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 + I d e n t i f y I m a g e C o m m a n d %
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 % IdentifyImageCommand() describes the format and characteristics of one or
67 % more image files. It will also report if an image is incomplete or corrupt.
68 % The information displayed includes the scene number, the file name, the
69 % width and height of the image, whether the image is colormapped or not,
70 % the number of colors in the image, the number of bytes in the image, the
71 % format of the image (JPEG, PNM, etc.), and finally the number of seconds
72 % it took to read and process the image.
74 % The format of the IdentifyImageCommand method is:
76 % MagickBooleanType IdentifyImageCommand(ImageInfo *image_info,int argc,
77 % char **argv,char **metadata,ExceptionInfo *exception)
79 % A description of each parameter follows:
81 % o image_info: the image info.
83 % o argc: the number of elements in the argument vector.
85 % o argv: A text array containing the command line arguments.
87 % o metadata: any metadata is returned here.
89 % o exception: return any errors or warnings in this structure.
93 static MagickBooleanType IdentifyUsage(void)
101 "-debug events display copious debugging information",
102 "-help print program options",
103 "-list type print a list of supported option arguments",
104 "-log format format of debugging information",
105 "-version print version information",
110 "-negate replace every pixel with its complementary color ",
115 "-alpha option on, activate, off, deactivate, set, opaque, copy",
116 " transparent, extract, background, or shape",
117 "-antialias remove pixel-aliasing",
118 "-authenticate password",
119 " decipher image with this password",
120 "-channel type apply option to select image channels",
121 "-clip clip along the first path from the 8BIM profile",
122 "-clip-mask filename associate a clip mask with the image",
123 "-clip-path id clip along a named path from the 8BIM profile",
124 "-colorspace type alternate image colorspace",
125 "-crop geometry cut out a rectangular region of the image",
126 "-define format:option",
127 " define one or more image format options",
128 "-density geometry horizontal and vertical density of the image",
129 "-depth value image depth",
130 "-endian type endianness (MSB or LSB) of the image",
131 "-extract geometry extract area from image",
132 "-features distance analyze image features (e.g. contrast, correlation)",
133 "-format \"string\" output formatted image characteristics",
134 "-fuzz distance colors within this distance are considered equal",
135 "-gamma value of gamma correction",
136 "-interlace type type of image interlacing scheme",
137 "-interpolate method pixel color interpolation method",
138 "-limit type value pixel cache resource limit",
139 "-mask filename associate a mask with the image",
140 "-monitor monitor progress",
141 "-ping efficiently determine image attributes",
142 "-quiet suppress all warning messages",
143 "-regard-warnings pay attention to warning messages",
144 "-respect-parentheses settings remain in effect until parenthesis boundary",
145 "-sampling-factor geometry",
146 " horizontal and vertical sampling factor",
147 "-seed value seed a new sequence of pseudo-random numbers",
148 "-set attribute value set an image attribute",
149 "-size geometry width and height of image",
150 "-strip strip image of all profiles and comments",
151 "-unique display the number of unique colors in the image",
152 "-units type the units of image resolution",
153 "-verbose print detailed information about the image",
154 "-virtual-pixel method",
155 " virtual pixel access method",
159 ListMagickVersion(stdout);
160 (void) printf("Usage: %s [options ...] file [ [options ...] "
161 "file ... ]\n",GetClientName());
162 (void) printf("\nImage Settings:\n");
163 for (p=settings; *p != (char *) NULL; p++)
164 (void) printf(" %s\n",*p);
165 (void) printf("\nImage Operators:\n");
166 for (p=operators; *p != (char *) NULL; p++)
167 (void) printf(" %s\n",*p);
168 (void) printf("\nMiscellaneous Options:\n");
169 for (p=miscellaneous; *p != (char *) NULL; p++)
170 (void) printf(" %s\n",*p);
172 "\nBy default, the image format of 'file' is determined by its magic\n");
174 "number. To specify a particular image format, precede the filename\n");
176 "with an image format name and a colon (i.e. ps:image) or specify the\n");
178 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
179 (void) printf("'-' for standard input or output.\n");
183 WandExport MagickBooleanType IdentifyImageCommand(ImageInfo *image_info,
184 int argc,char **argv,char **metadata,ExceptionInfo *exception)
186 #define DestroyIdentify() \
188 DestroyImageStack(); \
189 for (i=0; i < (ssize_t) argc; i++) \
190 argv[i]=DestroyString(argv[i]); \
191 argv=(char **) RelinquishMagickMemory(argv); \
193 #define ThrowIdentifyException(asperity,tag,option) \
195 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
198 return(MagickFalse); \
200 #define ThrowIdentifyInvalidArgumentException(option,argument) \
202 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
203 "InvalidArgument","'%s': %s",option,argument); \
205 return(MagickFalse); \
216 image_stack[MaxImageStackDepth+1];
239 assert(image_info != (ImageInfo *) NULL);
240 assert(image_info->signature == MagickSignature);
241 if (image_info->debug != MagickFalse)
242 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
243 assert(exception != (ExceptionInfo *) NULL);
247 if ((LocaleCompare("version",option+1) == 0) ||
248 (LocaleCompare("-version",option+1) == 0))
250 ListMagickVersion(stdout);
255 return(IdentifyUsage());
261 option=(char *) NULL;
263 respect_parenthesis=MagickFalse;
268 ReadCommandlLine(argc,&argv);
269 status=ExpandFilenames(&argc,&argv);
270 if (status == MagickFalse)
271 ThrowIdentifyException(ResourceLimitError,"MemoryAllocationFailed",
272 GetExceptionMessage(errno));
273 image_info->ping=MagickTrue;
274 for (i=1; i < (ssize_t) argc; i++)
277 if (LocaleCompare(option,"(") == 0)
279 FireImageStack(MagickFalse,MagickTrue,pend);
280 if (k == MaxImageStackDepth)
281 ThrowIdentifyException(OptionError,"ParenthesisNestedTooDeeply",
286 if (LocaleCompare(option,")") == 0)
288 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
290 ThrowIdentifyException(OptionError,"UnableToParseExpression",option);
294 if (IsCommandOption(option) == MagickFalse)
308 FireImageStack(MagickFalse,MagickFalse,pend);
309 identify_info=CloneImageInfo(image_info);
310 identify_info->verbose=MagickFalse;
312 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
314 if (identify_info->ping != MagickFalse)
315 images=PingImages(identify_info,filename,exception);
317 images=ReadImages(identify_info,filename,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);
325 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
327 if (image->scene == 0)
328 image->scene=count++;
329 if (format == (char *) NULL)
331 (void) IdentifyImage(image,stdout,image_info->verbose,exception);
334 if (metadata != (char **) NULL)
339 text=InterpretImageProperties(image_info,image,format,exception);
340 if (text == (char *) NULL)
341 ThrowIdentifyException(ResourceLimitError,
342 "MemoryAllocationFailed",GetExceptionMessage(errno));
343 (void) ConcatenateString(&(*metadata),text);
344 text=DestroyString(text);
345 if (LocaleCompare(format,"%n") == 0)
349 RemoveAllImageStack();
352 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
357 if (LocaleCompare("alpha",option+1) == 0)
365 if (i == (ssize_t) argc)
366 ThrowIdentifyException(OptionError,"MissingArgument",option);
367 type=ParseCommandOption(MagickAlphaChannelOptions,MagickFalse,
370 ThrowIdentifyException(OptionError,
371 "UnrecognizedAlphaChannelOption",argv[i]);
374 if (LocaleCompare("antialias",option+1) == 0)
376 if (LocaleCompare("authenticate",option+1) == 0)
381 if (i == (ssize_t) (argc-1))
382 ThrowIdentifyException(OptionError,"MissingArgument",option);
385 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
389 if (LocaleCompare("cache",option+1) == 0)
394 if (i == (ssize_t) argc)
395 ThrowIdentifyException(OptionError,"MissingArgument",option);
396 if (IsGeometry(argv[i]) == MagickFalse)
397 ThrowIdentifyInvalidArgumentException(option,argv[i]);
400 if (LocaleCompare("channel",option+1) == 0)
408 if (i == (ssize_t) (argc-1))
409 ThrowIdentifyException(OptionError,"MissingArgument",option);
410 channel=ParseChannelOption(argv[i]);
412 ThrowIdentifyException(OptionError,"UnrecognizedChannelType",
416 if (LocaleCompare("clip",option+1) == 0)
418 if (LocaleCompare("clip-mask",option+1) == 0)
423 if (i == (ssize_t) (argc-1))
424 ThrowIdentifyException(OptionError,"MissingArgument",option);
427 if (LocaleCompare("clip-path",option+1) == 0)
430 if (i == (ssize_t) (argc-1))
431 ThrowIdentifyException(OptionError,"MissingArgument",option);
434 if (LocaleCompare("colorspace",option+1) == 0)
442 if (i == (ssize_t) (argc-1))
443 ThrowIdentifyException(OptionError,"MissingArgument",option);
444 colorspace=ParseCommandOption(MagickColorspaceOptions,
445 MagickFalse,argv[i]);
447 ThrowIdentifyException(OptionError,"UnrecognizedColorspace",
451 if (LocaleCompare("crop",option+1) == 0)
456 if (i == (ssize_t) (argc-1))
457 ThrowIdentifyException(OptionError,"MissingArgument",option);
458 if (IsGeometry(argv[i]) == MagickFalse)
459 ThrowIdentifyInvalidArgumentException(option,argv[i]);
460 image_info->ping=MagickFalse;
463 if (LocaleCompare("concurrent",option+1) == 0)
465 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
469 if (LocaleCompare("debug",option+1) == 0)
477 if (i == (ssize_t) argc)
478 ThrowIdentifyException(OptionError,"MissingArgument",option);
479 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
481 ThrowIdentifyException(OptionError,"UnrecognizedEventType",
483 (void) SetLogEventMask(argv[i]);
486 if (LocaleCompare("define",option+1) == 0)
489 if (i == (ssize_t) argc)
490 ThrowIdentifyException(OptionError,"MissingArgument",option);
496 define=GetImageOption(image_info,argv[i]);
497 if (define == (const char *) NULL)
498 ThrowIdentifyException(OptionError,"NoSuchOption",argv[i]);
503 if (LocaleCompare("density",option+1) == 0)
508 if (i == (ssize_t) argc)
509 ThrowIdentifyException(OptionError,"MissingArgument",option);
510 if (IsGeometry(argv[i]) == MagickFalse)
511 ThrowIdentifyInvalidArgumentException(option,argv[i]);
514 if (LocaleCompare("depth",option+1) == 0)
519 if (i == (ssize_t) argc)
520 ThrowIdentifyException(OptionError,"MissingArgument",option);
521 if (IsGeometry(argv[i]) == MagickFalse)
522 ThrowIdentifyInvalidArgumentException(option,argv[i]);
525 if (LocaleCompare("duration",option+1) == 0)
530 if (i == (ssize_t) (argc-1))
531 ThrowIdentifyException(OptionError,"MissingArgument",option);
532 if (IsGeometry(argv[i]) == MagickFalse)
533 ThrowIdentifyInvalidArgumentException(option,argv[i]);
536 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
540 if (LocaleCompare("endian",option+1) == 0)
548 if (i == (ssize_t) (argc-1))
549 ThrowIdentifyException(OptionError,"MissingArgument",option);
550 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,
553 ThrowIdentifyException(OptionError,"UnrecognizedEndianType",
557 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
561 if (LocaleCompare("features",option+1) == 0)
566 if (i == (ssize_t) (argc-1))
567 ThrowIdentifyException(OptionError,"MissingArgument",option);
568 if (IsGeometry(argv[i]) == MagickFalse)
569 ThrowIdentifyInvalidArgumentException(option,argv[i]);
572 if (LocaleCompare("format",option+1) == 0)
574 format=(char *) NULL;
578 if (i == (ssize_t) argc)
579 ThrowIdentifyException(OptionError,"MissingArgument",option);
583 if (LocaleCompare("fuzz",option+1) == 0)
588 if (i == (ssize_t) (argc-1))
589 ThrowIdentifyException(OptionError,"MissingArgument",option);
590 if (IsGeometry(argv[i]) == MagickFalse)
591 ThrowIdentifyInvalidArgumentException(option,argv[i]);
594 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
598 if (LocaleCompare("gamma",option+1) == 0)
601 if (i == (ssize_t) (argc-1))
602 ThrowIdentifyException(OptionError,"MissingArgument",option);
603 if (IsGeometry(argv[i]) == MagickFalse)
604 ThrowIdentifyInvalidArgumentException(option,argv[i]);
607 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
611 if ((LocaleCompare("help",option+1) == 0) ||
612 (LocaleCompare("-help",option+1) == 0))
613 return(IdentifyUsage());
614 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
618 if (LocaleCompare("interlace",option+1) == 0)
626 if (i == (ssize_t) argc)
627 ThrowIdentifyException(OptionError,"MissingArgument",option);
628 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
631 ThrowIdentifyException(OptionError,
632 "UnrecognizedInterlaceType",argv[i]);
635 if (LocaleCompare("interpolate",option+1) == 0)
643 if (i == (ssize_t) argc)
644 ThrowIdentifyException(OptionError,"MissingArgument",option);
645 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
648 ThrowIdentifyException(OptionError,
649 "UnrecognizedInterpolateMethod",argv[i]);
652 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
656 if (LocaleCompare("limit",option+1) == 0)
670 if (i == (ssize_t) argc)
671 ThrowIdentifyException(OptionError,"MissingArgument",option);
672 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
675 ThrowIdentifyException(OptionError,"UnrecognizedResourceType",
678 if (i == (ssize_t) argc)
679 ThrowIdentifyException(OptionError,"MissingArgument",option);
680 value=StringToDouble(argv[i],&p);
682 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
683 ThrowIdentifyInvalidArgumentException(option,argv[i]);
686 if (LocaleCompare("list",option+1) == 0)
694 if (i == (ssize_t) argc)
695 ThrowIdentifyException(OptionError,"MissingArgument",option);
696 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
698 ThrowIdentifyException(OptionError,"UnrecognizedListType",
700 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
703 return(status != 0 ? MagickFalse : MagickTrue);
705 if (LocaleCompare("log",option+1) == 0)
710 if ((i == (ssize_t) argc) ||
711 (strchr(argv[i],'%') == (char *) NULL))
712 ThrowIdentifyException(OptionError,"MissingArgument",option);
715 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
719 if (LocaleCompare("mask",option+1) == 0)
724 if (i == (ssize_t) (argc-1))
725 ThrowIdentifyException(OptionError,"MissingArgument",option);
728 if (LocaleCompare("matte",option+1) == 0)
730 if (LocaleCompare("monitor",option+1) == 0)
732 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
736 if (LocaleCompare("negate",option+1) == 0)
738 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
742 if (LocaleCompare("ping",option+1) == 0)
744 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
748 if (LocaleCompare("quiet",option+1) == 0)
750 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
754 if (LocaleCompare("regard-warnings",option+1) == 0)
756 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
758 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
761 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
765 if (LocaleCompare("sampling-factor",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 if (LocaleCompare("seed",option+1) == 0)
781 if (i == (ssize_t) (argc-1))
782 ThrowIdentifyException(OptionError,"MissingArgument",option);
783 if (IsGeometry(argv[i]) == MagickFalse)
784 ThrowIdentifyInvalidArgumentException(option,argv[i]);
787 if (LocaleCompare("set",option+1) == 0)
790 if (i == (ssize_t) argc)
791 ThrowIdentifyException(OptionError,"MissingArgument",option);
795 if (i == (ssize_t) argc)
796 ThrowIdentifyException(OptionError,"MissingArgument",option);
799 if (LocaleCompare("size",option+1) == 0)
804 if (i == (ssize_t) argc)
805 ThrowIdentifyException(OptionError,"MissingArgument",option);
806 if (IsGeometry(argv[i]) == MagickFalse)
807 ThrowIdentifyInvalidArgumentException(option,argv[i]);
810 if (LocaleCompare("strip",option+1) == 0)
812 if (LocaleCompare("support",option+1) == 0)
817 if (i == (ssize_t) argc)
818 ThrowIdentifyException(OptionError,"MissingArgument",option);
819 if (IsGeometry(argv[i]) == MagickFalse)
820 ThrowIdentifyInvalidArgumentException(option,argv[i]);
823 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
827 if (LocaleCompare("unique",option+1) == 0)
829 if (LocaleCompare("units",option+1) == 0)
837 if (i == (ssize_t) (argc-1))
838 ThrowIdentifyException(OptionError,"MissingArgument",option);
839 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
842 ThrowIdentifyException(OptionError,"UnrecognizedUnitsType",
846 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
850 if (LocaleCompare("verbose",option+1) == 0)
852 if (LocaleCompare("virtual-pixel",option+1) == 0)
860 if (i == (ssize_t) (argc-1))
861 ThrowIdentifyException(OptionError,"MissingArgument",option);
862 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
865 ThrowIdentifyException(OptionError,
866 "UnrecognizedVirtualPixelMethod",argv[i]);
869 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
874 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
876 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
877 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
878 if (fire != MagickFalse)
879 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
882 ThrowIdentifyException(OptionError,"UnbalancedParenthesis",argv[i]);
883 if (i != (ssize_t) argc)
884 ThrowIdentifyException(OptionError,"MissingAnImageFilename",argv[i]);
886 return(status != 0 ? MagickTrue : MagickFalse);