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 "wand/studio.h"
51 #include "wand/MagickWand.h"
52 #include "wand/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) fprintf(stdout,"Version: %s\n",
247 GetMagickVersion((size_t *) NULL));
248 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
249 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
254 return(IdentifyUsage());
260 option=(char *) NULL;
262 respect_parenthesis=MagickFalse;
267 ReadCommandlLine(argc,&argv);
268 status=ExpandFilenames(&argc,&argv);
269 if (status == MagickFalse)
270 ThrowIdentifyException(ResourceLimitError,"MemoryAllocationFailed",
271 GetExceptionMessage(errno));
272 image_info->ping=MagickTrue;
273 for (i=1; i < (ssize_t) argc; i++)
276 if (LocaleCompare(option,"(") == 0)
278 FireImageStack(MagickFalse,MagickTrue,pend);
279 if (k == MaxImageStackDepth)
280 ThrowIdentifyException(OptionError,"ParenthesisNestedTooDeeply",
285 if (LocaleCompare(option,")") == 0)
287 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
289 ThrowIdentifyException(OptionError,"UnableToParseExpression",option);
293 if (IsCommandOption(option) == MagickFalse)
307 FireImageStack(MagickFalse,MagickFalse,pend);
308 identify_info=CloneImageInfo(image_info);
309 identify_info->verbose=MagickFalse;
311 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
313 (void) CopyMagickString(identify_info->filename,filename,MaxTextExtent);
314 if (identify_info->ping != MagickFalse)
315 images=PingImages(identify_info,exception);
317 images=ReadImages(identify_info,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);
334 if (metadata != (char **) NULL)
339 text=InterpretImageProperties(image_info,image,format);
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(MagickAlphaOptions,MagickFalse,argv[i]);
369 ThrowIdentifyException(OptionError,"UnrecognizedAlphaChannelType",
373 if (LocaleCompare("antialias",option+1) == 0)
375 if (LocaleCompare("authenticate",option+1) == 0)
380 if (i == (ssize_t) (argc-1))
381 ThrowIdentifyException(OptionError,"MissingArgument",option);
384 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
388 if (LocaleCompare("cache",option+1) == 0)
393 if (i == (ssize_t) argc)
394 ThrowIdentifyException(OptionError,"MissingArgument",option);
395 if (IsGeometry(argv[i]) == MagickFalse)
396 ThrowIdentifyInvalidArgumentException(option,argv[i]);
399 if (LocaleCompare("channel",option+1) == 0)
407 if (i == (ssize_t) (argc-1))
408 ThrowIdentifyException(OptionError,"MissingArgument",option);
409 channel=ParseChannelOption(argv[i]);
411 ThrowIdentifyException(OptionError,"UnrecognizedChannelType",
415 if (LocaleCompare("colorspace",option+1) == 0)
423 if (i == (ssize_t) (argc-1))
424 ThrowIdentifyException(OptionError,"MissingArgument",option);
425 colorspace=ParseCommandOption(MagickColorspaceOptions,
426 MagickFalse,argv[i]);
428 ThrowIdentifyException(OptionError,"UnrecognizedColorspace",
432 if (LocaleCompare("crop",option+1) == 0)
437 if (i == (ssize_t) (argc-1))
438 ThrowIdentifyException(OptionError,"MissingArgument",option);
439 if (IsGeometry(argv[i]) == MagickFalse)
440 ThrowIdentifyInvalidArgumentException(option,argv[i]);
441 image_info->ping=MagickFalse;
444 if (LocaleCompare("concurrent",option+1) == 0)
446 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
450 if (LocaleCompare("debug",option+1) == 0)
458 if (i == (ssize_t) argc)
459 ThrowIdentifyException(OptionError,"MissingArgument",option);
460 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
462 ThrowIdentifyException(OptionError,"UnrecognizedEventType",
464 (void) SetLogEventMask(argv[i]);
467 if (LocaleCompare("define",option+1) == 0)
470 if (i == (ssize_t) argc)
471 ThrowIdentifyException(OptionError,"MissingArgument",option);
477 define=GetImageOption(image_info,argv[i]);
478 if (define == (const char *) NULL)
479 ThrowIdentifyException(OptionError,"NoSuchOption",argv[i]);
484 if (LocaleCompare("density",option+1) == 0)
489 if (i == (ssize_t) argc)
490 ThrowIdentifyException(OptionError,"MissingArgument",option);
491 if (IsGeometry(argv[i]) == MagickFalse)
492 ThrowIdentifyInvalidArgumentException(option,argv[i]);
495 if (LocaleCompare("depth",option+1) == 0)
500 if (i == (ssize_t) argc)
501 ThrowIdentifyException(OptionError,"MissingArgument",option);
502 if (IsGeometry(argv[i]) == MagickFalse)
503 ThrowIdentifyInvalidArgumentException(option,argv[i]);
506 if (LocaleCompare("duration",option+1) == 0)
511 if (i == (ssize_t) (argc-1))
512 ThrowIdentifyException(OptionError,"MissingArgument",option);
513 if (IsGeometry(argv[i]) == MagickFalse)
514 ThrowIdentifyInvalidArgumentException(option,argv[i]);
517 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
521 if (LocaleCompare("features",option+1) == 0)
526 if (i == (ssize_t) (argc-1))
527 ThrowIdentifyException(OptionError,"MissingArgument",option);
528 if (IsGeometry(argv[i]) == MagickFalse)
529 ThrowIdentifyInvalidArgumentException(option,argv[i]);
532 if (LocaleCompare("format",option+1) == 0)
534 format=(char *) NULL;
538 if (i == (ssize_t) argc)
539 ThrowIdentifyException(OptionError,"MissingArgument",option);
543 if (LocaleCompare("fuzz",option+1) == 0)
548 if (i == (ssize_t) (argc-1))
549 ThrowIdentifyException(OptionError,"MissingArgument",option);
550 if (IsGeometry(argv[i]) == MagickFalse)
551 ThrowIdentifyInvalidArgumentException(option,argv[i]);
554 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
558 if (LocaleCompare("gamma",option+1) == 0)
561 if (i == (ssize_t) (argc-1))
562 ThrowIdentifyException(OptionError,"MissingArgument",option);
563 if (IsGeometry(argv[i]) == MagickFalse)
564 ThrowIdentifyInvalidArgumentException(option,argv[i]);
567 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
571 if ((LocaleCompare("help",option+1) == 0) ||
572 (LocaleCompare("-help",option+1) == 0))
573 return(IdentifyUsage());
574 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
578 if (LocaleCompare("interlace",option+1) == 0)
586 if (i == (ssize_t) argc)
587 ThrowIdentifyException(OptionError,"MissingArgument",option);
588 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
591 ThrowIdentifyException(OptionError,
592 "UnrecognizedInterlaceType",argv[i]);
595 if (LocaleCompare("interpolate",option+1) == 0)
603 if (i == (ssize_t) argc)
604 ThrowIdentifyException(OptionError,"MissingArgument",option);
605 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
608 ThrowIdentifyException(OptionError,
609 "UnrecognizedInterpolateMethod",argv[i]);
612 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
616 if (LocaleCompare("limit",option+1) == 0)
630 if (i == (ssize_t) argc)
631 ThrowIdentifyException(OptionError,"MissingArgument",option);
632 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
635 ThrowIdentifyException(OptionError,"UnrecognizedResourceType",
638 if (i == (ssize_t) argc)
639 ThrowIdentifyException(OptionError,"MissingArgument",option);
640 value=strtod(argv[i],&p);
642 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
643 ThrowIdentifyInvalidArgumentException(option,argv[i]);
646 if (LocaleCompare("list",option+1) == 0)
654 if (i == (ssize_t) argc)
655 ThrowIdentifyException(OptionError,"MissingArgument",option);
656 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
658 ThrowIdentifyException(OptionError,"UnrecognizedListType",
660 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
663 return(status != 0 ? MagickFalse : MagickTrue);
665 if (LocaleCompare("log",option+1) == 0)
670 if ((i == (ssize_t) argc) ||
671 (strchr(argv[i],'%') == (char *) NULL))
672 ThrowIdentifyException(OptionError,"MissingArgument",option);
675 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
679 if (LocaleCompare("matte",option+1) == 0)
681 if (LocaleCompare("monitor",option+1) == 0)
683 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
687 if (LocaleCompare("negate",option+1) == 0)
689 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
693 if (LocaleCompare("ping",option+1) == 0)
695 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
699 if (LocaleCompare("quiet",option+1) == 0)
701 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
705 if (LocaleCompare("regard-warnings",option+1) == 0)
707 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
709 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
712 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
716 if (LocaleCompare("sampling-factor",option+1) == 0)
721 if (i == (ssize_t) argc)
722 ThrowIdentifyException(OptionError,"MissingArgument",option);
723 if (IsGeometry(argv[i]) == MagickFalse)
724 ThrowIdentifyInvalidArgumentException(option,argv[i]);
727 if (LocaleCompare("seed",option+1) == 0)
732 if (i == (ssize_t) (argc-1))
733 ThrowIdentifyException(OptionError,"MissingArgument",option);
734 if (IsGeometry(argv[i]) == MagickFalse)
735 ThrowIdentifyInvalidArgumentException(option,argv[i]);
738 if (LocaleCompare("set",option+1) == 0)
741 if (i == (ssize_t) argc)
742 ThrowIdentifyException(OptionError,"MissingArgument",option);
746 if (i == (ssize_t) argc)
747 ThrowIdentifyException(OptionError,"MissingArgument",option);
750 if (LocaleCompare("size",option+1) == 0)
755 if (i == (ssize_t) argc)
756 ThrowIdentifyException(OptionError,"MissingArgument",option);
757 if (IsGeometry(argv[i]) == MagickFalse)
758 ThrowIdentifyInvalidArgumentException(option,argv[i]);
761 if (LocaleCompare("strip",option+1) == 0)
763 if (LocaleCompare("support",option+1) == 0)
768 if (i == (ssize_t) argc)
769 ThrowIdentifyException(OptionError,"MissingArgument",option);
770 if (IsGeometry(argv[i]) == MagickFalse)
771 ThrowIdentifyInvalidArgumentException(option,argv[i]);
774 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
778 if (LocaleCompare("unique",option+1) == 0)
780 if (LocaleCompare("units",option+1) == 0)
788 if (i == (ssize_t) (argc-1))
789 ThrowIdentifyException(OptionError,"MissingArgument",option);
790 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
793 ThrowIdentifyException(OptionError,"UnrecognizedUnitsType",
797 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
801 if (LocaleCompare("verbose",option+1) == 0)
803 if (LocaleCompare("virtual-pixel",option+1) == 0)
811 if (i == (ssize_t) (argc-1))
812 ThrowIdentifyException(OptionError,"MissingArgument",option);
813 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
816 ThrowIdentifyException(OptionError,
817 "UnrecognizedVirtualPixelMethod",argv[i]);
820 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
825 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
827 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
828 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
829 if (fire != MagickFalse)
830 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
833 ThrowIdentifyException(OptionError,"UnbalancedParenthesis",argv[i]);
834 if (i != (ssize_t) argc)
835 ThrowIdentifyException(OptionError,"MissingAnImageFilename",argv[i]);
837 return(status != 0 ? MagickTrue : MagickFalse);