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"
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59 + I d e n t i f y I m a g e C o m m a n d %
63 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 % IdentifyImageCommand() describes the format and characteristics of one or
66 % more image files. It will also report if an image is incomplete or corrupt.
67 % The information displayed includes the scene number, the file name, the
68 % width and height of the image, whether the image is colormapped or not,
69 % the number of colors in the image, the number of bytes in the image, the
70 % format of the image (JPEG, PNM, etc.), and finally the number of seconds
71 % it took to read and process the image.
73 % The format of the IdentifyImageCommand method is:
75 % MagickBooleanType IdentifyImageCommand(ImageInfo *image_info,int argc,
76 % char **argv,char **metadata,ExceptionInfo *exception)
78 % A description of each parameter follows:
80 % o image_info: the image info.
82 % o argc: the number of elements in the argument vector.
84 % o argv: A text array containing the command line arguments.
86 % o metadata: any metadata is returned here.
88 % o exception: return any errors or warnings in this structure.
92 static MagickBooleanType IdentifyUsage(void)
100 "-debug events display copious debugging information",
101 "-help print program options",
102 "-list type print a list of supported option arguments",
103 "-log format format of debugging information",
104 "-version print version information",
109 "-negate replace every pixel with its complementary color ",
114 "-alpha option on, activate, off, deactivate, set, opaque, copy",
115 " transparent, extract, background, or shape",
116 "-antialias remove pixel-aliasing",
117 "-authenticate password",
118 " decipher image with this password",
119 "-channel type apply option to select image channels",
120 "-colorspace type alternate image colorspace",
121 "-crop geometry cut out a rectangular region of the image",
122 "-define format:option",
123 " define one or more image format options",
124 "-density geometry horizontal and vertical density of the image",
125 "-depth value image depth",
126 "-extract geometry extract area from image",
127 "-features distance display image features (e.g. contrast, correlation)",
128 "-format \"string\" output formatted image characteristics",
129 "-fuzz distance colors within this distance are considered equal",
130 "-gamma value of gamma correction",
131 "-interlace type type of image interlacing scheme",
132 "-interpolate method pixel color interpolation method",
133 "-limit type value pixel cache resource limit",
134 "-monitor monitor progress",
135 "-ping efficiently determine image attributes",
136 "-quiet suppress all warning messages",
137 "-regard-warnings pay attention to warning messages",
138 "-respect-parentheses settings remain in effect until parenthesis boundary",
139 "-sampling-factor geometry",
140 " horizontal and vertical sampling factor",
141 "-seed value seed a new sequence of pseudo-random numbers",
142 "-set attribute value set an image attribute",
143 "-size geometry width and height of image",
144 "-strip strip image of all profiles and comments",
145 "-unique display the number of unique colors in the image",
146 "-units type the units of image resolution",
147 "-verbose print detailed information about the image",
148 "-virtual-pixel method",
149 " virtual pixel access method",
153 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
154 (void) printf("Copyright: %s\n",GetMagickCopyright());
155 (void) printf("Features: %s\n\n",GetMagickFeatures());
156 (void) printf("Usage: %s [options ...] file [ [options ...] "
157 "file ... ]\n",GetClientName());
158 (void) printf("\nImage Settings:\n");
159 for (p=settings; *p != (char *) NULL; p++)
160 (void) printf(" %s\n",*p);
161 (void) printf("\nImage Operators:\n");
162 for (p=operators; *p != (char *) NULL; p++)
163 (void) printf(" %s\n",*p);
164 (void) printf("\nMiscellaneous Options:\n");
165 for (p=miscellaneous; *p != (char *) NULL; p++)
166 (void) printf(" %s\n",*p);
168 "\nBy default, the image format of `file' is determined by its magic\n");
170 "number. To specify a particular image format, precede the filename\n");
172 "with an image format name and a colon (i.e. ps:image) or specify the\n");
174 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
175 (void) printf("'-' for standard input or output.\n");
179 WandExport MagickBooleanType IdentifyImageCommand(ImageInfo *image_info,
180 int argc,char **argv,char **metadata,ExceptionInfo *exception)
182 #define DestroyIdentify() \
184 DestroyImageStack(); \
185 for (i=0; i < (ssize_t) argc; i++) \
186 argv[i]=DestroyString(argv[i]); \
187 argv=(char **) RelinquishMagickMemory(argv); \
189 #define ThrowIdentifyException(asperity,tag,option) \
191 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
194 return(MagickFalse); \
196 #define ThrowIdentifyInvalidArgumentException(option,argument) \
198 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
199 "InvalidArgument","`%s': %s",option,argument); \
201 return(MagickFalse); \
212 image_stack[MaxImageStackDepth+1];
235 assert(image_info != (ImageInfo *) NULL);
236 assert(image_info->signature == MagickSignature);
237 if (image_info->debug != MagickFalse)
238 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
239 assert(exception != (ExceptionInfo *) NULL);
243 if ((LocaleCompare("version",option+1) == 0) ||
244 (LocaleCompare("-version",option+1) == 0))
246 (void) FormatLocaleFile(stdout,"Version: %s\n",
247 GetMagickVersion((size_t *) NULL));
248 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
249 GetMagickCopyright());
250 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
251 GetMagickFeatures());
256 return(IdentifyUsage());
262 option=(char *) NULL;
264 respect_parenthesis=MagickFalse;
269 ReadCommandlLine(argc,&argv);
270 status=ExpandFilenames(&argc,&argv);
271 if (status == MagickFalse)
272 ThrowIdentifyException(ResourceLimitError,"MemoryAllocationFailed",
273 GetExceptionMessage(errno));
274 image_info->ping=MagickTrue;
275 for (i=1; i < (ssize_t) argc; i++)
278 if (LocaleCompare(option,"(") == 0)
280 FireImageStack(MagickFalse,MagickTrue,pend);
281 if (k == MaxImageStackDepth)
282 ThrowIdentifyException(OptionError,"ParenthesisNestedTooDeeply",
287 if (LocaleCompare(option,")") == 0)
289 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
291 ThrowIdentifyException(OptionError,"UnableToParseExpression",option);
295 if (IsCommandOption(option) == MagickFalse)
309 FireImageStack(MagickFalse,MagickFalse,pend);
310 identify_info=CloneImageInfo(image_info);
311 identify_info->verbose=MagickFalse;
313 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
315 (void) CopyMagickString(identify_info->filename,filename,MaxTextExtent);
316 if (identify_info->ping != MagickFalse)
317 images=PingImages(identify_info,exception);
319 images=ReadImages(identify_info,exception);
320 identify_info=DestroyImageInfo(identify_info);
321 status&=(images != (Image *) NULL) &&
322 (exception->severity < ErrorException);
323 if (images == (Image *) NULL)
325 AppendImageStack(images);
326 FinalizeImageSettings(image_info,image,MagickFalse);
327 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
329 if (image->scene == 0)
330 image->scene=count++;
331 if (format == (char *) NULL)
333 (void) IdentifyImage(image,stdout,image_info->verbose,exception);
336 if (metadata != (char **) NULL)
341 text=InterpretImageProperties(image_info,image,format,exception);
342 if (text == (char *) NULL)
343 ThrowIdentifyException(ResourceLimitError,
344 "MemoryAllocationFailed",GetExceptionMessage(errno));
345 (void) ConcatenateString(&(*metadata),text);
346 text=DestroyString(text);
347 if (LocaleCompare(format,"%n") == 0)
351 RemoveAllImageStack();
354 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
359 if (LocaleCompare("alpha",option+1) == 0)
367 if (i == (ssize_t) argc)
368 ThrowIdentifyException(OptionError,"MissingArgument",option);
369 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
371 ThrowIdentifyException(OptionError,"UnrecognizedAlphaChannelType",
375 if (LocaleCompare("antialias",option+1) == 0)
377 if (LocaleCompare("authenticate",option+1) == 0)
382 if (i == (ssize_t) (argc-1))
383 ThrowIdentifyException(OptionError,"MissingArgument",option);
386 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
390 if (LocaleCompare("cache",option+1) == 0)
395 if (i == (ssize_t) argc)
396 ThrowIdentifyException(OptionError,"MissingArgument",option);
397 if (IsGeometry(argv[i]) == MagickFalse)
398 ThrowIdentifyInvalidArgumentException(option,argv[i]);
401 if (LocaleCompare("channel",option+1) == 0)
409 if (i == (ssize_t) (argc-1))
410 ThrowIdentifyException(OptionError,"MissingArgument",option);
411 channel=ParseChannelOption(argv[i]);
413 ThrowIdentifyException(OptionError,"UnrecognizedChannelType",
417 if (LocaleCompare("colorspace",option+1) == 0)
425 if (i == (ssize_t) (argc-1))
426 ThrowIdentifyException(OptionError,"MissingArgument",option);
427 colorspace=ParseCommandOption(MagickColorspaceOptions,
428 MagickFalse,argv[i]);
430 ThrowIdentifyException(OptionError,"UnrecognizedColorspace",
434 if (LocaleCompare("crop",option+1) == 0)
439 if (i == (ssize_t) (argc-1))
440 ThrowIdentifyException(OptionError,"MissingArgument",option);
441 if (IsGeometry(argv[i]) == MagickFalse)
442 ThrowIdentifyInvalidArgumentException(option,argv[i]);
443 image_info->ping=MagickFalse;
446 if (LocaleCompare("concurrent",option+1) == 0)
448 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
452 if (LocaleCompare("debug",option+1) == 0)
460 if (i == (ssize_t) argc)
461 ThrowIdentifyException(OptionError,"MissingArgument",option);
462 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
464 ThrowIdentifyException(OptionError,"UnrecognizedEventType",
466 (void) SetLogEventMask(argv[i]);
469 if (LocaleCompare("define",option+1) == 0)
472 if (i == (ssize_t) argc)
473 ThrowIdentifyException(OptionError,"MissingArgument",option);
479 define=GetImageOption(image_info,argv[i]);
480 if (define == (const char *) NULL)
481 ThrowIdentifyException(OptionError,"NoSuchOption",argv[i]);
486 if (LocaleCompare("density",option+1) == 0)
491 if (i == (ssize_t) argc)
492 ThrowIdentifyException(OptionError,"MissingArgument",option);
493 if (IsGeometry(argv[i]) == MagickFalse)
494 ThrowIdentifyInvalidArgumentException(option,argv[i]);
497 if (LocaleCompare("depth",option+1) == 0)
502 if (i == (ssize_t) argc)
503 ThrowIdentifyException(OptionError,"MissingArgument",option);
504 if (IsGeometry(argv[i]) == MagickFalse)
505 ThrowIdentifyInvalidArgumentException(option,argv[i]);
508 if (LocaleCompare("duration",option+1) == 0)
513 if (i == (ssize_t) (argc-1))
514 ThrowIdentifyException(OptionError,"MissingArgument",option);
515 if (IsGeometry(argv[i]) == MagickFalse)
516 ThrowIdentifyInvalidArgumentException(option,argv[i]);
519 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
523 if (LocaleCompare("features",option+1) == 0)
528 if (i == (ssize_t) (argc-1))
529 ThrowIdentifyException(OptionError,"MissingArgument",option);
530 if (IsGeometry(argv[i]) == MagickFalse)
531 ThrowIdentifyInvalidArgumentException(option,argv[i]);
534 if (LocaleCompare("format",option+1) == 0)
536 format=(char *) NULL;
540 if (i == (ssize_t) argc)
541 ThrowIdentifyException(OptionError,"MissingArgument",option);
545 if (LocaleCompare("fuzz",option+1) == 0)
550 if (i == (ssize_t) (argc-1))
551 ThrowIdentifyException(OptionError,"MissingArgument",option);
552 if (IsGeometry(argv[i]) == MagickFalse)
553 ThrowIdentifyInvalidArgumentException(option,argv[i]);
556 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
560 if (LocaleCompare("gamma",option+1) == 0)
563 if (i == (ssize_t) (argc-1))
564 ThrowIdentifyException(OptionError,"MissingArgument",option);
565 if (IsGeometry(argv[i]) == MagickFalse)
566 ThrowIdentifyInvalidArgumentException(option,argv[i]);
569 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
573 if ((LocaleCompare("help",option+1) == 0) ||
574 (LocaleCompare("-help",option+1) == 0))
575 return(IdentifyUsage());
576 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
580 if (LocaleCompare("interlace",option+1) == 0)
588 if (i == (ssize_t) argc)
589 ThrowIdentifyException(OptionError,"MissingArgument",option);
590 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
593 ThrowIdentifyException(OptionError,
594 "UnrecognizedInterlaceType",argv[i]);
597 if (LocaleCompare("interpolate",option+1) == 0)
605 if (i == (ssize_t) argc)
606 ThrowIdentifyException(OptionError,"MissingArgument",option);
607 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
610 ThrowIdentifyException(OptionError,
611 "UnrecognizedInterpolateMethod",argv[i]);
614 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
618 if (LocaleCompare("limit",option+1) == 0)
632 if (i == (ssize_t) argc)
633 ThrowIdentifyException(OptionError,"MissingArgument",option);
634 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
637 ThrowIdentifyException(OptionError,"UnrecognizedResourceType",
640 if (i == (ssize_t) argc)
641 ThrowIdentifyException(OptionError,"MissingArgument",option);
642 value=InterpretLocaleValue(argv[i],&p);
644 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
645 ThrowIdentifyInvalidArgumentException(option,argv[i]);
648 if (LocaleCompare("list",option+1) == 0)
656 if (i == (ssize_t) argc)
657 ThrowIdentifyException(OptionError,"MissingArgument",option);
658 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
660 ThrowIdentifyException(OptionError,"UnrecognizedListType",
662 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
665 return(status != 0 ? MagickFalse : MagickTrue);
667 if (LocaleCompare("log",option+1) == 0)
672 if ((i == (ssize_t) argc) ||
673 (strchr(argv[i],'%') == (char *) NULL))
674 ThrowIdentifyException(OptionError,"MissingArgument",option);
677 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
681 if (LocaleCompare("matte",option+1) == 0)
683 if (LocaleCompare("monitor",option+1) == 0)
685 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
689 if (LocaleCompare("negate",option+1) == 0)
691 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
695 if (LocaleCompare("ping",option+1) == 0)
697 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
701 if (LocaleCompare("quiet",option+1) == 0)
703 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
707 if (LocaleCompare("regard-warnings",option+1) == 0)
709 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
711 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
714 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
718 if (LocaleCompare("sampling-factor",option+1) == 0)
723 if (i == (ssize_t) argc)
724 ThrowIdentifyException(OptionError,"MissingArgument",option);
725 if (IsGeometry(argv[i]) == MagickFalse)
726 ThrowIdentifyInvalidArgumentException(option,argv[i]);
729 if (LocaleCompare("seed",option+1) == 0)
734 if (i == (ssize_t) (argc-1))
735 ThrowIdentifyException(OptionError,"MissingArgument",option);
736 if (IsGeometry(argv[i]) == MagickFalse)
737 ThrowIdentifyInvalidArgumentException(option,argv[i]);
740 if (LocaleCompare("set",option+1) == 0)
743 if (i == (ssize_t) argc)
744 ThrowIdentifyException(OptionError,"MissingArgument",option);
748 if (i == (ssize_t) argc)
749 ThrowIdentifyException(OptionError,"MissingArgument",option);
752 if (LocaleCompare("size",option+1) == 0)
757 if (i == (ssize_t) argc)
758 ThrowIdentifyException(OptionError,"MissingArgument",option);
759 if (IsGeometry(argv[i]) == MagickFalse)
760 ThrowIdentifyInvalidArgumentException(option,argv[i]);
763 if (LocaleCompare("strip",option+1) == 0)
765 if (LocaleCompare("support",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("unique",option+1) == 0)
782 if (LocaleCompare("units",option+1) == 0)
790 if (i == (ssize_t) (argc-1))
791 ThrowIdentifyException(OptionError,"MissingArgument",option);
792 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
795 ThrowIdentifyException(OptionError,"UnrecognizedUnitsType",
799 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
803 if (LocaleCompare("verbose",option+1) == 0)
805 if (LocaleCompare("virtual-pixel",option+1) == 0)
813 if (i == (ssize_t) (argc-1))
814 ThrowIdentifyException(OptionError,"MissingArgument",option);
815 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
818 ThrowIdentifyException(OptionError,
819 "UnrecognizedVirtualPixelMethod",argv[i]);
822 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
827 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
829 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
830 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
831 if (fire != MagickFalse)
832 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
835 ThrowIdentifyException(OptionError,"UnbalancedParenthesis",argv[i]);
836 if (i != (ssize_t) argc)
837 ThrowIdentifyException(OptionError,"MissingAnImageFilename",argv[i]);
839 return(status != 0 ? MagickTrue : MagickFalse);