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-2011 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 "-extract geometry extract area from image",
128 "-features distance display image features (e.g. contrast, correlation)",
129 "-format \"string\" output formatted image characteristics",
130 "-fuzz distance colors within this distance are considered equal",
131 "-gamma value of gamma correction",
132 "-interlace type type of image interlacing scheme",
133 "-interpolate method pixel color interpolation method",
134 "-limit type value pixel cache resource limit",
135 "-monitor monitor progress",
136 "-ping efficiently determine image attributes",
137 "-quiet suppress all warning messages",
138 "-regard-warnings pay attention to warning messages",
139 "-respect-parentheses settings remain in effect until parenthesis boundary",
140 "-sampling-factor geometry",
141 " horizontal and vertical sampling factor",
142 "-seed value seed a new sequence of pseudo-random numbers",
143 "-set attribute value set an image attribute",
144 "-size geometry width and height of image",
145 "-strip strip image of all profiles and comments",
146 "-unique display the number of unique colors in the image",
147 "-units type the units of image resolution",
148 "-verbose print detailed information about the image",
149 "-virtual-pixel method",
150 " virtual pixel access method",
154 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
155 (void) printf("Copyright: %s\n",GetMagickCopyright());
156 (void) printf("Features: %s\n\n",GetMagickFeatures());
157 (void) printf("Usage: %s [options ...] file [ [options ...] "
158 "file ... ]\n",GetClientName());
159 (void) printf("\nImage Settings:\n");
160 for (p=settings; *p != (char *) NULL; p++)
161 (void) printf(" %s\n",*p);
162 (void) printf("\nImage Operators:\n");
163 for (p=operators; *p != (char *) NULL; p++)
164 (void) printf(" %s\n",*p);
165 (void) printf("\nMiscellaneous Options:\n");
166 for (p=miscellaneous; *p != (char *) NULL; p++)
167 (void) printf(" %s\n",*p);
169 "\nBy default, the image format of `file' is determined by its magic\n");
171 "number. To specify a particular image format, precede the filename\n");
173 "with an image format name and a colon (i.e. ps:image) or specify the\n");
175 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
176 (void) printf("'-' for standard input or output.\n");
180 WandExport MagickBooleanType IdentifyImageCommand(ImageInfo *image_info,
181 int argc,char **argv,char **metadata,ExceptionInfo *exception)
183 #define DestroyIdentify() \
185 DestroyImageStack(); \
186 for (i=0; i < (ssize_t) argc; i++) \
187 argv[i]=DestroyString(argv[i]); \
188 argv=(char **) RelinquishMagickMemory(argv); \
190 #define ThrowIdentifyException(asperity,tag,option) \
192 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
195 return(MagickFalse); \
197 #define ThrowIdentifyInvalidArgumentException(option,argument) \
199 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
200 "InvalidArgument","`%s': %s",option,argument); \
202 return(MagickFalse); \
213 image_stack[MaxImageStackDepth+1];
236 assert(image_info != (ImageInfo *) NULL);
237 assert(image_info->signature == MagickSignature);
238 if (image_info->debug != MagickFalse)
239 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
240 assert(exception != (ExceptionInfo *) NULL);
244 if ((LocaleCompare("version",option+1) == 0) ||
245 (LocaleCompare("-version",option+1) == 0))
247 (void) FormatLocaleFile(stdout,"Version: %s\n",
248 GetMagickVersion((size_t *) NULL));
249 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
250 GetMagickCopyright());
251 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
252 GetMagickFeatures());
257 return(IdentifyUsage());
263 option=(char *) NULL;
265 respect_parenthesis=MagickFalse;
270 ReadCommandlLine(argc,&argv);
271 status=ExpandFilenames(&argc,&argv);
272 if (status == MagickFalse)
273 ThrowIdentifyException(ResourceLimitError,"MemoryAllocationFailed",
274 GetExceptionMessage(errno));
275 image_info->ping=MagickTrue;
276 for (i=1; i < (ssize_t) argc; i++)
279 if (LocaleCompare(option,"(") == 0)
281 FireImageStack(MagickFalse,MagickTrue,pend);
282 if (k == MaxImageStackDepth)
283 ThrowIdentifyException(OptionError,"ParenthesisNestedTooDeeply",
288 if (LocaleCompare(option,")") == 0)
290 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
292 ThrowIdentifyException(OptionError,"UnableToParseExpression",option);
296 if (IsCommandOption(option) == MagickFalse)
310 FireImageStack(MagickFalse,MagickFalse,pend);
311 identify_info=CloneImageInfo(image_info);
312 identify_info->verbose=MagickFalse;
314 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
316 (void) CopyMagickString(identify_info->filename,filename,MaxTextExtent);
317 if (identify_info->ping != MagickFalse)
318 images=PingImages(identify_info,exception);
320 images=ReadImages(identify_info,exception);
321 identify_info=DestroyImageInfo(identify_info);
322 status&=(images != (Image *) NULL) &&
323 (exception->severity < ErrorException);
324 if (images == (Image *) NULL)
326 AppendImageStack(images);
327 FinalizeImageSettings(image_info,image,MagickFalse);
328 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
330 if (image->scene == 0)
331 image->scene=count++;
332 if (format == (char *) NULL)
334 (void) IdentifyImage(image,stdout,image_info->verbose,exception);
337 if (metadata != (char **) NULL)
342 text=InterpretImageProperties(image_info,image,format,exception);
343 if (text == (char *) NULL)
344 ThrowIdentifyException(ResourceLimitError,
345 "MemoryAllocationFailed",GetExceptionMessage(errno));
346 (void) ConcatenateString(&(*metadata),text);
347 text=DestroyString(text);
348 if (LocaleCompare(format,"%n") == 0)
352 RemoveAllImageStack();
355 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
360 if (LocaleCompare("alpha",option+1) == 0)
368 if (i == (ssize_t) argc)
369 ThrowIdentifyException(OptionError,"MissingArgument",option);
370 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
372 ThrowIdentifyException(OptionError,"UnrecognizedAlphaChannelType",
376 if (LocaleCompare("antialias",option+1) == 0)
378 if (LocaleCompare("authenticate",option+1) == 0)
383 if (i == (ssize_t) (argc-1))
384 ThrowIdentifyException(OptionError,"MissingArgument",option);
387 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
391 if (LocaleCompare("cache",option+1) == 0)
396 if (i == (ssize_t) argc)
397 ThrowIdentifyException(OptionError,"MissingArgument",option);
398 if (IsGeometry(argv[i]) == MagickFalse)
399 ThrowIdentifyInvalidArgumentException(option,argv[i]);
402 if (LocaleCompare("channel",option+1) == 0)
410 if (i == (ssize_t) (argc-1))
411 ThrowIdentifyException(OptionError,"MissingArgument",option);
412 channel=ParseChannelOption(argv[i]);
414 ThrowIdentifyException(OptionError,"UnrecognizedChannelType",
418 if (LocaleCompare("colorspace",option+1) == 0)
426 if (i == (ssize_t) (argc-1))
427 ThrowIdentifyException(OptionError,"MissingArgument",option);
428 colorspace=ParseCommandOption(MagickColorspaceOptions,
429 MagickFalse,argv[i]);
431 ThrowIdentifyException(OptionError,"UnrecognizedColorspace",
435 if (LocaleCompare("crop",option+1) == 0)
440 if (i == (ssize_t) (argc-1))
441 ThrowIdentifyException(OptionError,"MissingArgument",option);
442 if (IsGeometry(argv[i]) == MagickFalse)
443 ThrowIdentifyInvalidArgumentException(option,argv[i]);
444 image_info->ping=MagickFalse;
447 if (LocaleCompare("concurrent",option+1) == 0)
449 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
453 if (LocaleCompare("debug",option+1) == 0)
461 if (i == (ssize_t) argc)
462 ThrowIdentifyException(OptionError,"MissingArgument",option);
463 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
465 ThrowIdentifyException(OptionError,"UnrecognizedEventType",
467 (void) SetLogEventMask(argv[i]);
470 if (LocaleCompare("define",option+1) == 0)
473 if (i == (ssize_t) argc)
474 ThrowIdentifyException(OptionError,"MissingArgument",option);
480 define=GetImageOption(image_info,argv[i]);
481 if (define == (const char *) NULL)
482 ThrowIdentifyException(OptionError,"NoSuchOption",argv[i]);
487 if (LocaleCompare("density",option+1) == 0)
492 if (i == (ssize_t) argc)
493 ThrowIdentifyException(OptionError,"MissingArgument",option);
494 if (IsGeometry(argv[i]) == MagickFalse)
495 ThrowIdentifyInvalidArgumentException(option,argv[i]);
498 if (LocaleCompare("depth",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("duration",option+1) == 0)
514 if (i == (ssize_t) (argc-1))
515 ThrowIdentifyException(OptionError,"MissingArgument",option);
516 if (IsGeometry(argv[i]) == MagickFalse)
517 ThrowIdentifyInvalidArgumentException(option,argv[i]);
520 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
524 if (LocaleCompare("features",option+1) == 0)
529 if (i == (ssize_t) (argc-1))
530 ThrowIdentifyException(OptionError,"MissingArgument",option);
531 if (IsGeometry(argv[i]) == MagickFalse)
532 ThrowIdentifyInvalidArgumentException(option,argv[i]);
535 if (LocaleCompare("format",option+1) == 0)
537 format=(char *) NULL;
541 if (i == (ssize_t) argc)
542 ThrowIdentifyException(OptionError,"MissingArgument",option);
546 if (LocaleCompare("fuzz",option+1) == 0)
551 if (i == (ssize_t) (argc-1))
552 ThrowIdentifyException(OptionError,"MissingArgument",option);
553 if (IsGeometry(argv[i]) == MagickFalse)
554 ThrowIdentifyInvalidArgumentException(option,argv[i]);
557 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
561 if (LocaleCompare("gamma",option+1) == 0)
564 if (i == (ssize_t) (argc-1))
565 ThrowIdentifyException(OptionError,"MissingArgument",option);
566 if (IsGeometry(argv[i]) == MagickFalse)
567 ThrowIdentifyInvalidArgumentException(option,argv[i]);
570 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
574 if ((LocaleCompare("help",option+1) == 0) ||
575 (LocaleCompare("-help",option+1) == 0))
576 return(IdentifyUsage());
577 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
581 if (LocaleCompare("interlace",option+1) == 0)
589 if (i == (ssize_t) argc)
590 ThrowIdentifyException(OptionError,"MissingArgument",option);
591 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
594 ThrowIdentifyException(OptionError,
595 "UnrecognizedInterlaceType",argv[i]);
598 if (LocaleCompare("interpolate",option+1) == 0)
606 if (i == (ssize_t) argc)
607 ThrowIdentifyException(OptionError,"MissingArgument",option);
608 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
611 ThrowIdentifyException(OptionError,
612 "UnrecognizedInterpolateMethod",argv[i]);
615 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
619 if (LocaleCompare("limit",option+1) == 0)
633 if (i == (ssize_t) argc)
634 ThrowIdentifyException(OptionError,"MissingArgument",option);
635 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
638 ThrowIdentifyException(OptionError,"UnrecognizedResourceType",
641 if (i == (ssize_t) argc)
642 ThrowIdentifyException(OptionError,"MissingArgument",option);
643 value=StringToDouble(argv[i],&p);
645 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
646 ThrowIdentifyInvalidArgumentException(option,argv[i]);
649 if (LocaleCompare("list",option+1) == 0)
657 if (i == (ssize_t) argc)
658 ThrowIdentifyException(OptionError,"MissingArgument",option);
659 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
661 ThrowIdentifyException(OptionError,"UnrecognizedListType",
663 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
666 return(status != 0 ? MagickFalse : MagickTrue);
668 if (LocaleCompare("log",option+1) == 0)
673 if ((i == (ssize_t) argc) ||
674 (strchr(argv[i],'%') == (char *) NULL))
675 ThrowIdentifyException(OptionError,"MissingArgument",option);
678 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
682 if (LocaleCompare("matte",option+1) == 0)
684 if (LocaleCompare("monitor",option+1) == 0)
686 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
690 if (LocaleCompare("negate",option+1) == 0)
692 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
696 if (LocaleCompare("ping",option+1) == 0)
698 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
702 if (LocaleCompare("quiet",option+1) == 0)
704 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
708 if (LocaleCompare("regard-warnings",option+1) == 0)
710 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
712 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
715 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
719 if (LocaleCompare("sampling-factor",option+1) == 0)
724 if (i == (ssize_t) argc)
725 ThrowIdentifyException(OptionError,"MissingArgument",option);
726 if (IsGeometry(argv[i]) == MagickFalse)
727 ThrowIdentifyInvalidArgumentException(option,argv[i]);
730 if (LocaleCompare("seed",option+1) == 0)
735 if (i == (ssize_t) (argc-1))
736 ThrowIdentifyException(OptionError,"MissingArgument",option);
737 if (IsGeometry(argv[i]) == MagickFalse)
738 ThrowIdentifyInvalidArgumentException(option,argv[i]);
741 if (LocaleCompare("set",option+1) == 0)
744 if (i == (ssize_t) argc)
745 ThrowIdentifyException(OptionError,"MissingArgument",option);
749 if (i == (ssize_t) argc)
750 ThrowIdentifyException(OptionError,"MissingArgument",option);
753 if (LocaleCompare("size",option+1) == 0)
758 if (i == (ssize_t) argc)
759 ThrowIdentifyException(OptionError,"MissingArgument",option);
760 if (IsGeometry(argv[i]) == MagickFalse)
761 ThrowIdentifyInvalidArgumentException(option,argv[i]);
764 if (LocaleCompare("strip",option+1) == 0)
766 if (LocaleCompare("support",option+1) == 0)
771 if (i == (ssize_t) argc)
772 ThrowIdentifyException(OptionError,"MissingArgument",option);
773 if (IsGeometry(argv[i]) == MagickFalse)
774 ThrowIdentifyInvalidArgumentException(option,argv[i]);
777 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
781 if (LocaleCompare("unique",option+1) == 0)
783 if (LocaleCompare("units",option+1) == 0)
791 if (i == (ssize_t) (argc-1))
792 ThrowIdentifyException(OptionError,"MissingArgument",option);
793 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
796 ThrowIdentifyException(OptionError,"UnrecognizedUnitsType",
800 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
804 if (LocaleCompare("verbose",option+1) == 0)
806 if (LocaleCompare("virtual-pixel",option+1) == 0)
814 if (i == (ssize_t) (argc-1))
815 ThrowIdentifyException(OptionError,"MissingArgument",option);
816 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
819 ThrowIdentifyException(OptionError,
820 "UnrecognizedVirtualPixelMethod",argv[i]);
823 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
828 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
830 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
831 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
832 if (fire != MagickFalse)
833 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
836 ThrowIdentifyException(OptionError,"UnbalancedParenthesis",argv[i]);
837 if (i != (ssize_t) argc)
838 ThrowIdentifyException(OptionError,"MissingAnImageFilename",argv[i]);
840 return(status != 0 ? MagickTrue : MagickFalse);