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-2010 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];
234 assert(image_info != (ImageInfo *) NULL);
235 assert(image_info->signature == MagickSignature);
236 if (image_info->debug != MagickFalse)
237 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
238 assert(exception != (ExceptionInfo *) NULL);
242 if ((LocaleCompare("version",option+1) == 0) ||
243 (LocaleCompare("-version",option+1) == 0))
245 (void) fprintf(stdout,"Version: %s\n",
246 GetMagickVersion((size_t *) NULL));
247 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
248 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
253 return(IdentifyUsage());
259 option=(char *) NULL;
265 ReadCommandlLine(argc,&argv);
266 status=ExpandFilenames(&argc,&argv);
267 if (status == MagickFalse)
268 ThrowIdentifyException(ResourceLimitError,"MemoryAllocationFailed",
269 GetExceptionMessage(errno));
270 image_info->ping=MagickTrue;
271 for (i=1; i < (ssize_t) argc; i++)
274 if (LocaleCompare(option,"(") == 0)
276 FireImageStack(MagickFalse,MagickTrue,pend);
277 if (k == MaxImageStackDepth)
278 ThrowIdentifyException(OptionError,"ParenthesisNestedTooDeeply",
283 if (LocaleCompare(option,")") == 0)
285 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
287 ThrowIdentifyException(OptionError,"UnableToParseExpression",option);
291 if (IsMagickOption(option) == MagickFalse)
305 FireImageStack(MagickFalse,MagickFalse,pend);
306 identify_info=CloneImageInfo(image_info);
307 identify_info->verbose=MagickFalse;
309 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
311 (void) CopyMagickString(identify_info->filename,filename,MaxTextExtent);
312 if (identify_info->ping != MagickFalse)
313 images=PingImages(identify_info,exception);
315 images=ReadImages(identify_info,exception);
316 identify_info=DestroyImageInfo(identify_info);
317 status&=(images != (Image *) NULL) &&
318 (exception->severity < ErrorException);
319 if (images == (Image *) NULL)
321 AppendImageStack(images);
322 FinalizeImageSettings(image_info,image,MagickFalse);
323 for ( ; image != (Image *) NULL; image=GetNextImageInList(image))
325 if (image->scene == 0)
326 image->scene=count++;
327 if (format == (char *) NULL)
329 (void) IdentifyImage(image,stdout,image_info->verbose);
332 if (metadata != (char **) NULL)
337 text=InterpretImageProperties(image_info,image,format);
338 if (text == (char *) NULL)
339 ThrowIdentifyException(ResourceLimitError,
340 "MemoryAllocationFailed",GetExceptionMessage(errno));
341 (void) ConcatenateString(&(*metadata),text);
342 text=DestroyString(text);
343 if (LocaleCompare(format,"%n") == 0)
347 RemoveAllImageStack();
350 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
355 if (LocaleCompare("alpha",option+1) == 0)
363 if (i == (ssize_t) argc)
364 ThrowIdentifyException(OptionError,"MissingArgument",option);
365 type=ParseMagickOption(MagickAlphaOptions,MagickFalse,argv[i]);
367 ThrowIdentifyException(OptionError,"UnrecognizedAlphaChannelType",
371 if (LocaleCompare("antialias",option+1) == 0)
373 if (LocaleCompare("authenticate",option+1) == 0)
378 if (i == (ssize_t) (argc-1))
379 ThrowIdentifyException(OptionError,"MissingArgument",option);
382 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
386 if (LocaleCompare("cache",option+1) == 0)
391 if (i == (ssize_t) argc)
392 ThrowIdentifyException(OptionError,"MissingArgument",option);
393 if (IsGeometry(argv[i]) == MagickFalse)
394 ThrowIdentifyInvalidArgumentException(option,argv[i]);
397 if (LocaleCompare("channel",option+1) == 0)
405 if (i == (ssize_t) (argc-1))
406 ThrowIdentifyException(OptionError,"MissingArgument",option);
407 channel=ParseChannelOption(argv[i]);
409 ThrowIdentifyException(OptionError,"UnrecognizedChannelType",
413 if (LocaleCompare("colorspace",option+1) == 0)
421 if (i == (ssize_t) (argc-1))
422 ThrowIdentifyException(OptionError,"MissingArgument",option);
423 colorspace=ParseMagickOption(MagickColorspaceOptions,
424 MagickFalse,argv[i]);
426 ThrowIdentifyException(OptionError,"UnrecognizedColorspace",
430 if (LocaleCompare("crop",option+1) == 0)
435 if (i == (ssize_t) (argc-1))
436 ThrowIdentifyException(OptionError,"MissingArgument",option);
437 if (IsGeometry(argv[i]) == MagickFalse)
438 ThrowIdentifyInvalidArgumentException(option,argv[i]);
439 image_info->ping=MagickFalse;
442 if (LocaleCompare("concurrent",option+1) == 0)
444 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
448 if (LocaleCompare("debug",option+1) == 0)
456 if (i == (ssize_t) argc)
457 ThrowIdentifyException(OptionError,"MissingArgument",option);
458 event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
460 ThrowIdentifyException(OptionError,"UnrecognizedEventType",
462 (void) SetLogEventMask(argv[i]);
465 if (LocaleCompare("define",option+1) == 0)
468 if (i == (ssize_t) argc)
469 ThrowIdentifyException(OptionError,"MissingArgument",option);
475 define=GetImageOption(image_info,argv[i]);
476 if (define == (const char *) NULL)
477 ThrowIdentifyException(OptionError,"NoSuchOption",argv[i]);
482 if (LocaleCompare("density",option+1) == 0)
487 if (i == (ssize_t) argc)
488 ThrowIdentifyException(OptionError,"MissingArgument",option);
489 if (IsGeometry(argv[i]) == MagickFalse)
490 ThrowIdentifyInvalidArgumentException(option,argv[i]);
493 if (LocaleCompare("depth",option+1) == 0)
498 if (i == (ssize_t) argc)
499 ThrowIdentifyException(OptionError,"MissingArgument",option);
500 if (IsGeometry(argv[i]) == MagickFalse)
501 ThrowIdentifyInvalidArgumentException(option,argv[i]);
504 if (LocaleCompare("duration",option+1) == 0)
509 if (i == (ssize_t) (argc-1))
510 ThrowIdentifyException(OptionError,"MissingArgument",option);
511 if (IsGeometry(argv[i]) == MagickFalse)
512 ThrowIdentifyInvalidArgumentException(option,argv[i]);
515 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
519 if (LocaleCompare("features",option+1) == 0)
524 if (i == (ssize_t) (argc-1))
525 ThrowIdentifyException(OptionError,"MissingArgument",option);
526 if (IsGeometry(argv[i]) == MagickFalse)
527 ThrowIdentifyInvalidArgumentException(option,argv[i]);
530 if (LocaleCompare("format",option+1) == 0)
532 format=(char *) NULL;
536 if (i == (ssize_t) argc)
537 ThrowIdentifyException(OptionError,"MissingArgument",option);
541 if (LocaleCompare("fuzz",option+1) == 0)
546 if (i == (ssize_t) (argc-1))
547 ThrowIdentifyException(OptionError,"MissingArgument",option);
548 if (IsGeometry(argv[i]) == MagickFalse)
549 ThrowIdentifyInvalidArgumentException(option,argv[i]);
552 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
556 if (LocaleCompare("gamma",option+1) == 0)
559 if (i == (ssize_t) (argc-1))
560 ThrowIdentifyException(OptionError,"MissingArgument",option);
561 if (IsGeometry(argv[i]) == MagickFalse)
562 ThrowIdentifyInvalidArgumentException(option,argv[i]);
565 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
569 if ((LocaleCompare("help",option+1) == 0) ||
570 (LocaleCompare("-help",option+1) == 0))
571 return(IdentifyUsage());
572 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
576 if (LocaleCompare("interlace",option+1) == 0)
584 if (i == (ssize_t) argc)
585 ThrowIdentifyException(OptionError,"MissingArgument",option);
586 interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
589 ThrowIdentifyException(OptionError,
590 "UnrecognizedInterlaceType",argv[i]);
593 if (LocaleCompare("interpolate",option+1) == 0)
601 if (i == (ssize_t) argc)
602 ThrowIdentifyException(OptionError,"MissingArgument",option);
603 interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
606 ThrowIdentifyException(OptionError,
607 "UnrecognizedInterpolateMethod",argv[i]);
610 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
614 if (LocaleCompare("limit",option+1) == 0)
628 if (i == (ssize_t) argc)
629 ThrowIdentifyException(OptionError,"MissingArgument",option);
630 resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
633 ThrowIdentifyException(OptionError,"UnrecognizedResourceType",
636 if (i == (ssize_t) argc)
637 ThrowIdentifyException(OptionError,"MissingArgument",option);
638 value=strtod(argv[i],&p);
639 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
640 ThrowIdentifyInvalidArgumentException(option,argv[i]);
643 if (LocaleCompare("list",option+1) == 0)
651 if (i == (ssize_t) argc)
652 ThrowIdentifyException(OptionError,"MissingArgument",option);
653 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
655 ThrowIdentifyException(OptionError,"UnrecognizedListType",
657 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
660 return(status != 0 ? MagickFalse : MagickTrue);
662 if (LocaleCompare("log",option+1) == 0)
667 if ((i == (ssize_t) argc) ||
668 (strchr(argv[i],'%') == (char *) NULL))
669 ThrowIdentifyException(OptionError,"MissingArgument",option);
672 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
676 if (LocaleCompare("matte",option+1) == 0)
678 if (LocaleCompare("monitor",option+1) == 0)
680 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
684 if (LocaleCompare("negate",option+1) == 0)
686 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
690 if (LocaleCompare("ping",option+1) == 0)
692 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
696 if (LocaleCompare("quiet",option+1) == 0)
698 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
702 if (LocaleCompare("regard-warnings",option+1) == 0)
704 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
706 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
709 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
713 if (LocaleCompare("sampling-factor",option+1) == 0)
718 if (i == (ssize_t) argc)
719 ThrowIdentifyException(OptionError,"MissingArgument",option);
720 if (IsGeometry(argv[i]) == MagickFalse)
721 ThrowIdentifyInvalidArgumentException(option,argv[i]);
724 if (LocaleCompare("seed",option+1) == 0)
729 if (i == (ssize_t) (argc-1))
730 ThrowIdentifyException(OptionError,"MissingArgument",option);
731 if (IsGeometry(argv[i]) == MagickFalse)
732 ThrowIdentifyInvalidArgumentException(option,argv[i]);
735 if (LocaleCompare("set",option+1) == 0)
738 if (i == (ssize_t) argc)
739 ThrowIdentifyException(OptionError,"MissingArgument",option);
743 if (i == (ssize_t) argc)
744 ThrowIdentifyException(OptionError,"MissingArgument",option);
747 if (LocaleCompare("size",option+1) == 0)
752 if (i == (ssize_t) argc)
753 ThrowIdentifyException(OptionError,"MissingArgument",option);
754 if (IsGeometry(argv[i]) == MagickFalse)
755 ThrowIdentifyInvalidArgumentException(option,argv[i]);
758 if (LocaleCompare("strip",option+1) == 0)
760 if (LocaleCompare("support",option+1) == 0)
765 if (i == (ssize_t) argc)
766 ThrowIdentifyException(OptionError,"MissingArgument",option);
767 if (IsGeometry(argv[i]) == MagickFalse)
768 ThrowIdentifyInvalidArgumentException(option,argv[i]);
771 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
775 if (LocaleCompare("unique",option+1) == 0)
777 if (LocaleCompare("units",option+1) == 0)
785 if (i == (ssize_t) (argc-1))
786 ThrowIdentifyException(OptionError,"MissingArgument",option);
787 units=ParseMagickOption(MagickResolutionOptions,MagickFalse,
790 ThrowIdentifyException(OptionError,"UnrecognizedUnitsType",
794 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
798 if (LocaleCompare("verbose",option+1) == 0)
800 if (LocaleCompare("virtual-pixel",option+1) == 0)
808 if (i == (ssize_t) (argc-1))
809 ThrowIdentifyException(OptionError,"MissingArgument",option);
810 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
813 ThrowIdentifyException(OptionError,
814 "UnrecognizedVirtualPixelMethod",argv[i]);
817 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
822 ThrowIdentifyException(OptionError,"UnrecognizedOption",option)
824 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
825 MagickFalse : MagickTrue;
826 if (fire != MagickFalse)
827 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
830 ThrowIdentifyException(OptionError,"UnbalancedParenthesis",argv[i]);
831 if (i != (ssize_t) argc)
832 ThrowIdentifyException(OptionError,"MissingAnImageFilename",argv[i]);
834 return(status != 0 ? MagickTrue : MagickFalse);