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-2014 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 "-grayscale method convert image to grayscale",
111 "-negate replace every pixel with its complementary color ",
116 "-alpha option on, activate, off, deactivate, set, opaque, copy",
117 " transparent, extract, background, or shape",
118 "-antialias remove pixel-aliasing",
119 "-authenticate password",
120 " decipher image with this password",
121 "-channel type apply option to select image channels",
122 "-clip clip along the first path from the 8BIM profile",
123 "-clip-mask filename associate a clip mask with the image",
124 "-clip-path id clip along a named path from the 8BIM profile",
125 "-colorspace type alternate image colorspace",
126 "-crop geometry cut out a rectangular region of the image",
127 "-define format:option",
128 " define one or more image format options",
129 "-density geometry horizontal and vertical density of the image",
130 "-depth value image depth",
131 "-endian type endianness (MSB or LSB) of the image",
132 "-extract geometry extract area from image",
133 "-features distance analyze image features (e.g. contrast, correlation)",
134 "-format \"string\" output formatted image characteristics",
135 "-fuzz distance colors within this distance are considered equal",
136 "-gamma value of gamma correction",
137 "-interlace type type of image interlacing scheme",
138 "-interpolate method pixel color interpolation method",
139 "-limit type value pixel cache resource limit",
140 "-mask filename associate a mask with the image",
141 "-matte store matte channel if the image has one",
142 "-moments report image moments",
143 "-monitor monitor progress",
144 "-ping efficiently determine image attributes",
145 "-precision value maximum number of significant digits to print",
146 "-quiet suppress all warning messages",
147 "-regard-warnings pay attention to warning messages",
148 "-respect-parentheses settings remain in effect until parenthesis boundary",
149 "-sampling-factor geometry",
150 " horizontal and vertical sampling factor",
151 "-seed value seed a new sequence of pseudo-random numbers",
152 "-set attribute value set an image attribute",
153 "-size geometry width and height of image",
154 "-strip strip image of all profiles and comments",
155 "-unique display the number of unique colors in the image",
156 "-units type the units of image resolution",
157 "-verbose print detailed information about the image",
158 "-virtual-pixel method",
159 " virtual pixel access method",
163 ListMagickVersion(stdout);
164 (void) printf("Usage: %s [options ...] file [ [options ...] "
165 "file ... ]\n",GetClientName());
166 (void) printf("\nImage Settings:\n");
167 for (p=settings; *p != (char *) NULL; p++)
168 (void) printf(" %s\n",*p);
169 (void) printf("\nImage Operators:\n");
170 for (p=operators; *p != (char *) NULL; p++)
171 (void) printf(" %s\n",*p);
172 (void) printf("\nMiscellaneous Options:\n");
173 for (p=miscellaneous; *p != (char *) NULL; p++)
174 (void) printf(" %s\n",*p);
176 "\nBy default, the image format of 'file' is determined by its magic\n");
178 "number. To specify a particular image format, precede the filename\n");
180 "with an image format name and a colon (i.e. ps:image) or specify the\n");
182 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
183 (void) printf("'-' for standard input or output.\n");
187 WandExport MagickBooleanType IdentifyImageCommand(ImageInfo *image_info,
188 int argc,char **argv,char **metadata,ExceptionInfo *exception)
190 #define DestroyIdentify() \
192 DestroyImageStack(); \
193 for (i=0; i < (ssize_t) argc; i++) \
194 argv[i]=DestroyString(argv[i]); \
195 argv=(char **) RelinquishMagickMemory(argv); \
197 #define ThrowIdentifyException(asperity,tag,option) \
199 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
202 return(MagickFalse); \
204 #define ThrowIdentifyInvalidArgumentException(option,argument) \
206 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
207 "InvalidArgument","'%s': %s",option,argument); \
209 return(MagickFalse); \
220 image_stack[MaxImageStackDepth+1];
243 assert(image_info != (ImageInfo *) NULL);
244 assert(image_info->signature == MagickSignature);
245 if (image_info->debug != MagickFalse)
246 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
247 assert(exception != (ExceptionInfo *) NULL);
251 if ((LocaleCompare("version",option+1) == 0) ||
252 (LocaleCompare("-version",option+1) == 0))
254 ListMagickVersion(stdout);
259 return(IdentifyUsage());
265 option=(char *) NULL;
267 respect_parenthesis=MagickFalse;
272 ReadCommandlLine(argc,&argv);
273 status=ExpandFilenames(&argc,&argv);
274 if (status == MagickFalse)
275 ThrowIdentifyException(ResourceLimitError,"MemoryAllocationFailed",
276 GetExceptionMessage(errno));
277 image_info->ping=MagickTrue;
278 for (i=1; i < (ssize_t) argc; i++)
281 if (LocaleCompare(option,"(") == 0)
283 FireImageStack(MagickFalse,MagickTrue,pend);
284 if (k == MaxImageStackDepth)
285 ThrowIdentifyException(OptionError,"ParenthesisNestedTooDeeply",
290 if (LocaleCompare(option,")") == 0)
292 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
294 ThrowIdentifyException(OptionError,"UnableToParseExpression",option);
298 if (IsCommandOption(option) == MagickFalse)
312 FireImageStack(MagickFalse,MagickFalse,pend);
313 identify_info=CloneImageInfo(image_info);
314 identify_info->verbose=MagickFalse;
316 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
318 if (identify_info->ping != MagickFalse)
319 images=PingImages(identify_info,filename,exception);
321 images=ReadImages(identify_info,filename,exception);
322 identify_info=DestroyImageInfo(identify_info);
323 status&=(images != (Image *) NULL) &&
324 (exception->severity < ErrorException);
325 if (images == (Image *) NULL)
327 AppendImageStack(images);
328 FinalizeImageSettings(image_info,image,MagickFalse);
329 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
331 if (image->scene == 0)
332 image->scene=count++;
333 if (format == (char *) NULL)
335 (void) IdentifyImage(image,stdout,image_info->verbose,exception);
338 if (metadata != (char **) NULL)
343 text=InterpretImageProperties(image_info,image,format,exception);
344 if (text == (char *) NULL)
345 ThrowIdentifyException(ResourceLimitError,
346 "MemoryAllocationFailed",GetExceptionMessage(errno));
347 (void) ConcatenateString(&(*metadata),text);
348 text=DestroyString(text);
349 if (GlobExpression(format,"*%n*",MagickFalse) != MagickFalse)
353 RemoveAllImageStack();
356 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
361 if (LocaleCompare("alpha",option+1) == 0)
369 if (i == (ssize_t) argc)
370 ThrowIdentifyException(OptionError,"MissingArgument",option);
371 type=ParseCommandOption(MagickAlphaChannelOptions,MagickFalse,
374 ThrowIdentifyException(OptionError,
375 "UnrecognizedAlphaChannelOption",argv[i]);
378 if (LocaleCompare("antialias",option+1) == 0)
380 if (LocaleCompare("authenticate",option+1) == 0)
385 if (i == (ssize_t) (argc-1))
386 ThrowIdentifyException(OptionError,"MissingArgument",option);
389 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
393 if (LocaleCompare("cache",option+1) == 0)
398 if (i == (ssize_t) argc)
399 ThrowIdentifyException(OptionError,"MissingArgument",option);
400 if (IsGeometry(argv[i]) == MagickFalse)
401 ThrowIdentifyInvalidArgumentException(option,argv[i]);
404 if (LocaleCompare("channel",option+1) == 0)
412 if (i == (ssize_t) (argc-1))
413 ThrowIdentifyException(OptionError,"MissingArgument",option);
414 channel=ParseChannelOption(argv[i]);
416 ThrowIdentifyException(OptionError,"UnrecognizedChannelType",
420 if (LocaleCompare("clip",option+1) == 0)
422 if (LocaleCompare("clip-mask",option+1) == 0)
427 if (i == (ssize_t) (argc-1))
428 ThrowIdentifyException(OptionError,"MissingArgument",option);
431 if (LocaleCompare("clip-path",option+1) == 0)
434 if (i == (ssize_t) (argc-1))
435 ThrowIdentifyException(OptionError,"MissingArgument",option);
438 if (LocaleCompare("colorspace",option+1) == 0)
446 if (i == (ssize_t) (argc-1))
447 ThrowIdentifyException(OptionError,"MissingArgument",option);
448 colorspace=ParseCommandOption(MagickColorspaceOptions,
449 MagickFalse,argv[i]);
451 ThrowIdentifyException(OptionError,"UnrecognizedColorspace",
455 if (LocaleCompare("crop",option+1) == 0)
460 if (i == (ssize_t) (argc-1))
461 ThrowIdentifyException(OptionError,"MissingArgument",option);
462 if (IsGeometry(argv[i]) == MagickFalse)
463 ThrowIdentifyInvalidArgumentException(option,argv[i]);
464 image_info->ping=MagickFalse;
467 if (LocaleCompare("concurrent",option+1) == 0)
469 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
473 if (LocaleCompare("debug",option+1) == 0)
481 if (i == (ssize_t) argc)
482 ThrowIdentifyException(OptionError,"MissingArgument",option);
483 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
485 ThrowIdentifyException(OptionError,"UnrecognizedEventType",
487 (void) SetLogEventMask(argv[i]);
490 if (LocaleCompare("define",option+1) == 0)
493 if (i == (ssize_t) argc)
494 ThrowIdentifyException(OptionError,"MissingArgument",option);
500 define=GetImageOption(image_info,argv[i]);
501 if (define == (const char *) NULL)
502 ThrowIdentifyException(OptionError,"NoSuchOption",argv[i]);
505 if (LocaleNCompare("identify:locate",argv[i],14) == 0)
506 image_info->ping=MagickFalse;
509 if (LocaleCompare("density",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("depth",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 if (LocaleCompare("duration",option+1) == 0)
536 if (i == (ssize_t) (argc-1))
537 ThrowIdentifyException(OptionError,"MissingArgument",option);
538 if (IsGeometry(argv[i]) == MagickFalse)
539 ThrowIdentifyInvalidArgumentException(option,argv[i]);
542 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
546 if (LocaleCompare("endian",option+1) == 0)
554 if (i == (ssize_t) (argc-1))
555 ThrowIdentifyException(OptionError,"MissingArgument",option);
556 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,
559 ThrowIdentifyException(OptionError,"UnrecognizedEndianType",
563 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
567 if (LocaleCompare("features",option+1) == 0)
572 if (i == (ssize_t) (argc-1))
573 ThrowIdentifyException(OptionError,"MissingArgument",option);
574 if (IsGeometry(argv[i]) == MagickFalse)
575 ThrowIdentifyInvalidArgumentException(option,argv[i]);
578 if (LocaleCompare("format",option+1) == 0)
580 format=(char *) NULL;
584 if (i == (ssize_t) argc)
585 ThrowIdentifyException(OptionError,"MissingArgument",option);
589 if (LocaleCompare("fuzz",option+1) == 0)
594 if (i == (ssize_t) (argc-1))
595 ThrowIdentifyException(OptionError,"MissingArgument",option);
596 if (IsGeometry(argv[i]) == MagickFalse)
597 ThrowIdentifyInvalidArgumentException(option,argv[i]);
600 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
604 if (LocaleCompare("gamma",option+1) == 0)
607 if (i == (ssize_t) (argc-1))
608 ThrowIdentifyException(OptionError,"MissingArgument",option);
609 if (IsGeometry(argv[i]) == MagickFalse)
610 ThrowIdentifyInvalidArgumentException(option,argv[i]);
613 if (LocaleCompare("grayscale",option+1) == 0)
621 if (i == (ssize_t) (argc-1))
622 ThrowIdentifyException(OptionError,"MissingArgument",option);
623 method=ParseCommandOption(MagickPixelIntensityOptions,MagickFalse,
626 ThrowIdentifyException(OptionError,"UnrecognizedIntensityMethod",
630 if (LocaleCompare("green-primary",option+1) == 0)
635 if (i == (ssize_t) (argc-1))
636 ThrowIdentifyException(OptionError,"MissingArgument",option);
637 if (IsGeometry(argv[i]) == MagickFalse)
638 ThrowIdentifyInvalidArgumentException(option,argv[i]);
641 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
645 if ((LocaleCompare("help",option+1) == 0) ||
646 (LocaleCompare("-help",option+1) == 0))
647 return(IdentifyUsage());
648 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
652 if (LocaleCompare("interlace",option+1) == 0)
660 if (i == (ssize_t) argc)
661 ThrowIdentifyException(OptionError,"MissingArgument",option);
662 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
665 ThrowIdentifyException(OptionError,
666 "UnrecognizedInterlaceType",argv[i]);
669 if (LocaleCompare("interpolate",option+1) == 0)
677 if (i == (ssize_t) argc)
678 ThrowIdentifyException(OptionError,"MissingArgument",option);
679 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
682 ThrowIdentifyException(OptionError,
683 "UnrecognizedInterpolateMethod",argv[i]);
686 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
690 if (LocaleCompare("limit",option+1) == 0)
704 if (i == (ssize_t) argc)
705 ThrowIdentifyException(OptionError,"MissingArgument",option);
706 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
709 ThrowIdentifyException(OptionError,"UnrecognizedResourceType",
712 if (i == (ssize_t) argc)
713 ThrowIdentifyException(OptionError,"MissingArgument",option);
714 value=StringToDouble(argv[i],&p);
716 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
717 ThrowIdentifyInvalidArgumentException(option,argv[i]);
720 if (LocaleCompare("list",option+1) == 0)
728 if (i == (ssize_t) argc)
729 ThrowIdentifyException(OptionError,"MissingArgument",option);
730 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
732 ThrowIdentifyException(OptionError,"UnrecognizedListType",
734 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
737 return(status != 0 ? MagickFalse : MagickTrue);
739 if (LocaleCompare("log",option+1) == 0)
744 if ((i == (ssize_t) argc) ||
745 (strchr(argv[i],'%') == (char *) NULL))
746 ThrowIdentifyException(OptionError,"MissingArgument",option);
749 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
753 if (LocaleCompare("mask",option+1) == 0)
758 if (i == (ssize_t) (argc-1))
759 ThrowIdentifyException(OptionError,"MissingArgument",option);
762 if (LocaleCompare("matte",option+1) == 0)
764 if (LocaleCompare("moments",option+1) == 0)
766 if (LocaleCompare("monitor",option+1) == 0)
768 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
772 if (LocaleCompare("negate",option+1) == 0)
774 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
778 if (LocaleCompare("ping",option+1) == 0)
780 if (LocaleCompare("precision",option+1) == 0)
785 if (i == (ssize_t) (argc-1))
786 ThrowIdentifyException(OptionError,"MissingArgument",option);
787 if (IsGeometry(argv[i]) == MagickFalse)
788 ThrowIdentifyInvalidArgumentException(option,argv[i]);
791 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
795 if (LocaleCompare("quiet",option+1) == 0)
797 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
801 if (LocaleCompare("regard-warnings",option+1) == 0)
803 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
805 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
808 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
812 if (LocaleCompare("sampling-factor",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 if (LocaleCompare("seed",option+1) == 0)
828 if (i == (ssize_t) (argc-1))
829 ThrowIdentifyException(OptionError,"MissingArgument",option);
830 if (IsGeometry(argv[i]) == MagickFalse)
831 ThrowIdentifyInvalidArgumentException(option,argv[i]);
834 if (LocaleCompare("set",option+1) == 0)
837 if (i == (ssize_t) argc)
838 ThrowIdentifyException(OptionError,"MissingArgument",option);
842 if (i == (ssize_t) argc)
843 ThrowIdentifyException(OptionError,"MissingArgument",option);
846 if (LocaleCompare("size",option+1) == 0)
851 if (i == (ssize_t) argc)
852 ThrowIdentifyException(OptionError,"MissingArgument",option);
853 if (IsGeometry(argv[i]) == MagickFalse)
854 ThrowIdentifyInvalidArgumentException(option,argv[i]);
857 if (LocaleCompare("strip",option+1) == 0)
859 if (LocaleCompare("support",option+1) == 0)
864 if (i == (ssize_t) argc)
865 ThrowIdentifyException(OptionError,"MissingArgument",option);
866 if (IsGeometry(argv[i]) == MagickFalse)
867 ThrowIdentifyInvalidArgumentException(option,argv[i]);
870 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
874 if (LocaleCompare("unique",option+1) == 0)
876 if (LocaleCompare("units",option+1) == 0)
884 if (i == (ssize_t) (argc-1))
885 ThrowIdentifyException(OptionError,"MissingArgument",option);
886 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
889 ThrowIdentifyException(OptionError,"UnrecognizedUnitsType",
893 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
897 if (LocaleCompare("verbose",option+1) == 0)
899 if (LocaleCompare("virtual-pixel",option+1) == 0)
907 if (i == (ssize_t) (argc-1))
908 ThrowIdentifyException(OptionError,"MissingArgument",option);
909 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
912 ThrowIdentifyException(OptionError,
913 "UnrecognizedVirtualPixelMethod",argv[i]);
916 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
921 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
923 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
924 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
925 if (fire != MagickFalse)
926 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
929 ThrowIdentifyException(OptionError,"UnbalancedParenthesis",argv[i]);
930 if (i != (ssize_t) argc)
931 ThrowIdentifyException(OptionError,"MissingAnImageFilename",argv[i]);
933 return(status != 0 ? MagickTrue : MagickFalse);