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 "-colorspace type alternate image colorspace",
122 "-crop geometry cut out a rectangular region of the image",
123 "-define format:option",
124 " define one or more image format options",
125 "-density geometry horizontal and vertical density of the image",
126 "-depth value image depth",
127 "-endian type endianness (MSB or LSB) of the image",
128 "-extract geometry extract area from image",
129 "-features distance analyze image features (e.g. contrast, correlation)",
130 "-format \"string\" output formatted image characteristics",
131 "-fuzz distance colors within this distance are considered equal",
132 "-gamma value of gamma correction",
133 "-interlace type type of image interlacing scheme",
134 "-interpolate method pixel color interpolation method",
135 "-limit type value pixel cache resource limit",
136 "-mask filename associate a mask with the image",
137 "-monitor monitor progress",
138 "-ping efficiently determine image attributes",
139 "-quiet suppress all warning messages",
140 "-regard-warnings pay attention to warning messages",
141 "-respect-parentheses settings remain in effect until parenthesis boundary",
142 "-sampling-factor geometry",
143 " horizontal and vertical sampling factor",
144 "-seed value seed a new sequence of pseudo-random numbers",
145 "-set attribute value set an image attribute",
146 "-size geometry width and height of image",
147 "-strip strip image of all profiles and comments",
148 "-unique display the number of unique colors in the image",
149 "-units type the units of image resolution",
150 "-verbose print detailed information about the image",
151 "-virtual-pixel method",
152 " virtual pixel access method",
156 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
157 (void) printf("Copyright: %s\n",GetMagickCopyright());
158 (void) printf("Features: %s\n\n",GetMagickFeatures());
159 (void) printf("Usage: %s [options ...] file [ [options ...] "
160 "file ... ]\n",GetClientName());
161 (void) printf("\nImage Settings:\n");
162 for (p=settings; *p != (char *) NULL; p++)
163 (void) printf(" %s\n",*p);
164 (void) printf("\nImage Operators:\n");
165 for (p=operators; *p != (char *) NULL; p++)
166 (void) printf(" %s\n",*p);
167 (void) printf("\nMiscellaneous Options:\n");
168 for (p=miscellaneous; *p != (char *) NULL; p++)
169 (void) printf(" %s\n",*p);
171 "\nBy default, the image format of 'file' is determined by its magic\n");
173 "number. To specify a particular image format, precede the filename\n");
175 "with an image format name and a colon (i.e. ps:image) or specify the\n");
177 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
178 (void) printf("'-' for standard input or output.\n");
182 WandExport MagickBooleanType IdentifyImageCommand(ImageInfo *image_info,
183 int argc,char **argv,char **metadata,ExceptionInfo *exception)
185 #define DestroyIdentify() \
187 DestroyImageStack(); \
188 for (i=0; i < (ssize_t) argc; i++) \
189 argv[i]=DestroyString(argv[i]); \
190 argv=(char **) RelinquishMagickMemory(argv); \
192 #define ThrowIdentifyException(asperity,tag,option) \
194 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"'%s'", \
197 return(MagickFalse); \
199 #define ThrowIdentifyInvalidArgumentException(option,argument) \
201 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
202 "InvalidArgument","'%s': %s",option,argument); \
204 return(MagickFalse); \
215 image_stack[MaxImageStackDepth+1];
238 assert(image_info != (ImageInfo *) NULL);
239 assert(image_info->signature == MagickSignature);
240 if (image_info->debug != MagickFalse)
241 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
242 assert(exception != (ExceptionInfo *) NULL);
246 if ((LocaleCompare("version",option+1) == 0) ||
247 (LocaleCompare("-version",option+1) == 0))
249 (void) FormatLocaleFile(stdout,"Version: %s\n",
250 GetMagickVersion((size_t *) NULL));
251 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
252 GetMagickCopyright());
253 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
254 GetMagickFeatures());
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 (LocaleCompare(format,"%n") == 0)
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("colorspace",option+1) == 0)
428 if (i == (ssize_t) (argc-1))
429 ThrowIdentifyException(OptionError,"MissingArgument",option);
430 colorspace=ParseCommandOption(MagickColorspaceOptions,
431 MagickFalse,argv[i]);
433 ThrowIdentifyException(OptionError,"UnrecognizedColorspace",
437 if (LocaleCompare("crop",option+1) == 0)
442 if (i == (ssize_t) (argc-1))
443 ThrowIdentifyException(OptionError,"MissingArgument",option);
444 if (IsGeometry(argv[i]) == MagickFalse)
445 ThrowIdentifyInvalidArgumentException(option,argv[i]);
446 image_info->ping=MagickFalse;
449 if (LocaleCompare("concurrent",option+1) == 0)
451 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
455 if (LocaleCompare("debug",option+1) == 0)
463 if (i == (ssize_t) argc)
464 ThrowIdentifyException(OptionError,"MissingArgument",option);
465 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
467 ThrowIdentifyException(OptionError,"UnrecognizedEventType",
469 (void) SetLogEventMask(argv[i]);
472 if (LocaleCompare("define",option+1) == 0)
475 if (i == (ssize_t) argc)
476 ThrowIdentifyException(OptionError,"MissingArgument",option);
482 define=GetImageOption(image_info,argv[i]);
483 if (define == (const char *) NULL)
484 ThrowIdentifyException(OptionError,"NoSuchOption",argv[i]);
489 if (LocaleCompare("density",option+1) == 0)
494 if (i == (ssize_t) argc)
495 ThrowIdentifyException(OptionError,"MissingArgument",option);
496 if (IsGeometry(argv[i]) == MagickFalse)
497 ThrowIdentifyInvalidArgumentException(option,argv[i]);
500 if (LocaleCompare("depth",option+1) == 0)
505 if (i == (ssize_t) argc)
506 ThrowIdentifyException(OptionError,"MissingArgument",option);
507 if (IsGeometry(argv[i]) == MagickFalse)
508 ThrowIdentifyInvalidArgumentException(option,argv[i]);
511 if (LocaleCompare("duration",option+1) == 0)
516 if (i == (ssize_t) (argc-1))
517 ThrowIdentifyException(OptionError,"MissingArgument",option);
518 if (IsGeometry(argv[i]) == MagickFalse)
519 ThrowIdentifyInvalidArgumentException(option,argv[i]);
522 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
526 if (LocaleCompare("endian",option+1) == 0)
534 if (i == (ssize_t) (argc-1))
535 ThrowIdentifyException(OptionError,"MissingArgument",option);
536 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,
539 ThrowIdentifyException(OptionError,"UnrecognizedEndianType",
543 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
547 if (LocaleCompare("features",option+1) == 0)
552 if (i == (ssize_t) (argc-1))
553 ThrowIdentifyException(OptionError,"MissingArgument",option);
554 if (IsGeometry(argv[i]) == MagickFalse)
555 ThrowIdentifyInvalidArgumentException(option,argv[i]);
558 if (LocaleCompare("format",option+1) == 0)
560 format=(char *) NULL;
564 if (i == (ssize_t) argc)
565 ThrowIdentifyException(OptionError,"MissingArgument",option);
569 if (LocaleCompare("fuzz",option+1) == 0)
574 if (i == (ssize_t) (argc-1))
575 ThrowIdentifyException(OptionError,"MissingArgument",option);
576 if (IsGeometry(argv[i]) == MagickFalse)
577 ThrowIdentifyInvalidArgumentException(option,argv[i]);
580 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
584 if (LocaleCompare("gamma",option+1) == 0)
587 if (i == (ssize_t) (argc-1))
588 ThrowIdentifyException(OptionError,"MissingArgument",option);
589 if (IsGeometry(argv[i]) == MagickFalse)
590 ThrowIdentifyInvalidArgumentException(option,argv[i]);
593 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
597 if ((LocaleCompare("help",option+1) == 0) ||
598 (LocaleCompare("-help",option+1) == 0))
599 return(IdentifyUsage());
600 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
604 if (LocaleCompare("interlace",option+1) == 0)
612 if (i == (ssize_t) argc)
613 ThrowIdentifyException(OptionError,"MissingArgument",option);
614 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
617 ThrowIdentifyException(OptionError,
618 "UnrecognizedInterlaceType",argv[i]);
621 if (LocaleCompare("interpolate",option+1) == 0)
629 if (i == (ssize_t) argc)
630 ThrowIdentifyException(OptionError,"MissingArgument",option);
631 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
634 ThrowIdentifyException(OptionError,
635 "UnrecognizedInterpolateMethod",argv[i]);
638 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
642 if (LocaleCompare("limit",option+1) == 0)
656 if (i == (ssize_t) argc)
657 ThrowIdentifyException(OptionError,"MissingArgument",option);
658 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
661 ThrowIdentifyException(OptionError,"UnrecognizedResourceType",
664 if (i == (ssize_t) argc)
665 ThrowIdentifyException(OptionError,"MissingArgument",option);
666 value=StringToDouble(argv[i],&p);
668 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
669 ThrowIdentifyInvalidArgumentException(option,argv[i]);
672 if (LocaleCompare("list",option+1) == 0)
680 if (i == (ssize_t) argc)
681 ThrowIdentifyException(OptionError,"MissingArgument",option);
682 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
684 ThrowIdentifyException(OptionError,"UnrecognizedListType",
686 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
689 return(status != 0 ? MagickFalse : MagickTrue);
691 if (LocaleCompare("log",option+1) == 0)
696 if ((i == (ssize_t) argc) ||
697 (strchr(argv[i],'%') == (char *) NULL))
698 ThrowIdentifyException(OptionError,"MissingArgument",option);
701 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
705 if (LocaleCompare("mask",option+1) == 0)
710 if (i == (ssize_t) (argc-1))
711 ThrowIdentifyException(OptionError,"MissingArgument",option);
714 if (LocaleCompare("matte",option+1) == 0)
716 if (LocaleCompare("monitor",option+1) == 0)
718 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
722 if (LocaleCompare("negate",option+1) == 0)
724 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
728 if (LocaleCompare("ping",option+1) == 0)
730 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
734 if (LocaleCompare("quiet",option+1) == 0)
736 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
740 if (LocaleCompare("regard-warnings",option+1) == 0)
742 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
744 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
747 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
751 if (LocaleCompare("sampling-factor",option+1) == 0)
756 if (i == (ssize_t) argc)
757 ThrowIdentifyException(OptionError,"MissingArgument",option);
758 if (IsGeometry(argv[i]) == MagickFalse)
759 ThrowIdentifyInvalidArgumentException(option,argv[i]);
762 if (LocaleCompare("seed",option+1) == 0)
767 if (i == (ssize_t) (argc-1))
768 ThrowIdentifyException(OptionError,"MissingArgument",option);
769 if (IsGeometry(argv[i]) == MagickFalse)
770 ThrowIdentifyInvalidArgumentException(option,argv[i]);
773 if (LocaleCompare("set",option+1) == 0)
776 if (i == (ssize_t) argc)
777 ThrowIdentifyException(OptionError,"MissingArgument",option);
781 if (i == (ssize_t) argc)
782 ThrowIdentifyException(OptionError,"MissingArgument",option);
785 if (LocaleCompare("size",option+1) == 0)
790 if (i == (ssize_t) argc)
791 ThrowIdentifyException(OptionError,"MissingArgument",option);
792 if (IsGeometry(argv[i]) == MagickFalse)
793 ThrowIdentifyInvalidArgumentException(option,argv[i]);
796 if (LocaleCompare("strip",option+1) == 0)
798 if (LocaleCompare("support",option+1) == 0)
803 if (i == (ssize_t) argc)
804 ThrowIdentifyException(OptionError,"MissingArgument",option);
805 if (IsGeometry(argv[i]) == MagickFalse)
806 ThrowIdentifyInvalidArgumentException(option,argv[i]);
809 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
813 if (LocaleCompare("unique",option+1) == 0)
815 if (LocaleCompare("units",option+1) == 0)
823 if (i == (ssize_t) (argc-1))
824 ThrowIdentifyException(OptionError,"MissingArgument",option);
825 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
828 ThrowIdentifyException(OptionError,"UnrecognizedUnitsType",
832 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
836 if (LocaleCompare("verbose",option+1) == 0)
838 if (LocaleCompare("virtual-pixel",option+1) == 0)
846 if (i == (ssize_t) (argc-1))
847 ThrowIdentifyException(OptionError,"MissingArgument",option);
848 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
851 ThrowIdentifyException(OptionError,
852 "UnrecognizedVirtualPixelMethod",argv[i]);
855 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
860 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
862 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
863 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
864 if (fire != MagickFalse)
865 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
868 ThrowIdentifyException(OptionError,"UnbalancedParenthesis",argv[i]);
869 if (i != (ssize_t) argc)
870 ThrowIdentifyException(OptionError,"MissingAnImageFilename",argv[i]);
872 return(status != 0 ? MagickTrue : MagickFalse);