2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % IIIII M M PPPP OOO RRRR TTTTT %
7 % I MM MM P P O O R R T %
8 % I M M M PPPP O O RRRR T %
10 % IIIII M M P OOO R R T %
13 % Import Image from X11 Screen %
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 % Use the import program to capture some or all of an X server screen and
37 % save the image to a file.
44 #include "MagickWand/studio.h"
45 #include "MagickWand/MagickWand.h"
46 #include "MagickWand/mogrify-private.h"
47 #include "MagickCore/string-private.h"
48 #include "MagickCore/xwindow-private.h"
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 + I m p o r t I m a g e C o m m a n d %
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 % ImportImageCommand() reads an image from any visible window on an X server
62 % and outputs it as an image file. You can capture a single window, the
63 % entire screen, or any rectangular portion of the screen. You can use the
64 % display utility for redisplay, printing, editing, formatting, archiving,
65 % image processing, etc. of the captured image.</dd>
67 % The target window can be specified by id, name, or may be selected by
68 % clicking the mouse in the desired window. If you press a button and then
69 % drag, a rectangle will form which expands and contracts as the mouse moves.
70 % To save the portion of the screen defined by the rectangle, just release
71 % the button. The keyboard bell is rung once at the beginning of the screen
72 % capture and twice when it completes.
74 % The format of the ImportImageCommand method is:
76 % MagickBooleanType ImportImageCommand(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 ImportUsage(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 "-annotate geometry text",
111 " annotate the image with text",
112 "-colors value preferred number of colors in the image",
113 "-crop geometry preferred size and location of the cropped image",
114 "-encipher filename convert plain pixels to cipher pixels",
115 "-geometry geometry preferred size or location of the image",
116 "-help print program options",
117 "-monochrome transform image to black and white",
118 "-negate replace every pixel with its complementary color ",
119 "-repage geometry size and location of an image canvas",
120 "-quantize colorspace reduce colors in this colorspace",
121 "-resize geometry resize the image",
122 "-rotate degrees apply Paeth rotation to the image",
123 "-strip strip image of all profiles and comments",
124 "-thumbnail geometry create a thumbnail of the image",
125 "-transparent color make this color transparent within the image",
126 "-trim trim image edges",
127 "-type type image type",
132 "-adjoin join images into a single multi-image file",
133 "-border include window border in the output image",
134 "-channel type apply option to select image channels",
135 "-colorspace type alternate image colorspace",
136 "-comment string annotate image with comment",
137 "-compress type type of pixel compression when writing the image",
138 "-define format:option",
139 " define one or more image format options",
140 "-density geometry horizontal and vertical density of the image",
141 "-depth value image depth",
142 "-descend obtain image by descending window hierarchy",
143 "-display server X server to contact",
144 "-dispose method layer disposal method",
145 "-dither method apply error diffusion to image",
146 "-delay value display the next image after pausing",
147 "-encipher filename convert plain pixels to cipher pixels",
148 "-endian type endianness (MSB or LSB) of the image",
149 "-encoding type text encoding type",
150 "-filter type use this filter when resizing an image",
151 "-format \"string\" output formatted image characteristics",
152 "-frame include window manager frame",
153 "-gravity direction which direction to gravitate towards",
154 "-identify identify the format and characteristics of the image",
155 "-interlace type None, Line, Plane, or Partition",
156 "-interpolate method pixel color interpolation method",
157 "-label string assign a label to an image",
158 "-limit type value Area, Disk, Map, or Memory resource limit",
159 "-monitor monitor progress",
160 "-page geometry size and location of an image canvas",
161 "-pause value seconds delay between snapshots",
162 "-pointsize value font point size",
163 "-quality value JPEG/MIFF/PNG compression level",
164 "-quiet suppress all warning messages",
165 "-regard-warnings pay attention to warning messages",
166 "-respect-parentheses settings remain in effect until parenthesis boundary",
167 "-sampling-factor geometry",
168 " horizontal and vertical sampling factor",
169 "-scene value image scene number",
170 "-screen select image from root window",
171 "-seed value seed a new sequence of pseudo-random numbers",
172 "-set property value set an image property",
173 "-silent operate silently, i.e. don't ring any bells ",
174 "-snaps value number of screen snapshots",
175 "-synchronize synchronize image to storage device",
176 "-taint declare the image as modified",
177 "-transparent-color color",
178 " transparent color",
179 "-treedepth value color tree depth",
180 "-verbose print detailed information about the image",
181 "-virtual-pixel method",
182 " Constant, Edge, Mirror, or Tile",
183 "-window id select window with this id or name",
187 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
188 (void) printf("Copyright: %s\n",GetMagickCopyright());
189 (void) printf("Features: %s\n\n",GetMagickFeatures());
190 (void) printf("Usage: %s [options ...] [ file ]\n",
192 (void) printf("\nImage Settings:\n");
193 for (p=settings; *p != (char *) NULL; p++)
194 (void) printf(" %s\n",*p);
195 (void) printf("\nImage Operators:\n");
196 for (p=operators; *p != (char *) NULL; p++)
197 (void) printf(" %s\n",*p);
198 (void) printf("\nMiscellaneous Options:\n");
199 for (p=miscellaneous; *p != (char *) NULL; p++)
200 (void) printf(" %s\n",*p);
202 "\nBy default, 'file' is written in the MIFF image format. To\n");
204 "specify a particular image format, precede the filename with an image\n");
206 "format name and a colon (i.e. ps:image) or specify the image type as\n");
208 "the filename suffix (i.e. image.ps). Specify 'file' as '-' for\n");
209 (void) printf("standard input or output.\n");
213 static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
220 WandExport MagickBooleanType ImportImageCommand(ImageInfo *image_info,
221 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
223 #if defined(MAGICKCORE_X11_DELEGATE)
224 #define DestroyImport() \
226 XDestroyResourceInfo(&resource_info); \
227 if (display != (Display *) NULL) \
229 XCloseDisplay(display); \
230 display=(Display *) NULL; \
232 DestroyImageStack(); \
233 if (target_window != (char *) NULL) \
234 target_window=DestroyString(target_window); \
235 for (i=0; i < (ssize_t) argc; i++) \
236 argv[i]=DestroyString(argv[i]); \
237 argv=(char **) RelinquishMagickMemory(argv); \
239 #define ThrowImportException(asperity,tag,option) \
241 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
244 return(MagickFalse); \
246 #define ThrowImportInvalidArgumentException(option,argument) \
248 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
249 "InvalidArgument","`%s': %s",option,argument); \
251 return(MagickFalse); \
268 image_stack[MaxImageStackDepth+1];
301 assert(image_info != (ImageInfo *) NULL);
302 assert(image_info->signature == MagickSignature);
303 if (image_info->debug != MagickFalse)
304 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
305 assert(exception != (ExceptionInfo *) NULL);
309 if ((LocaleCompare("version",option+1) == 0) ||
310 (LocaleCompare("-version",option+1) == 0))
312 (void) FormatLocaleFile(stdout,"Version: %s\n",
313 GetMagickVersion((size_t *) NULL));
314 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
315 GetMagickCopyright());
316 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
317 GetMagickFeatures());
321 display=(Display *) NULL;
325 option=(char *) NULL;
327 resource_database=(XrmDatabase) NULL;
328 respect_parenthesis=MagickFalse;
329 (void) ResetMagickMemory(&resource_info,0,sizeof(resource_info));
330 server_name=(char *) NULL;
333 target_window=(char *) NULL;
335 Check for server name specified on the command line.
337 ReadCommandlLine(argc,&argv);
338 status=ExpandFilenames(&argc,&argv);
339 if (status == MagickFalse)
340 ThrowImportException(ResourceLimitError,"MemoryAllocationFailed",
341 GetExceptionMessage(errno));
342 for (i=1; i < (ssize_t) argc; i++)
345 Check command line for server name.
348 if (LocaleCompare("display",option+1) == 0)
351 User specified server name.
354 if (i == (ssize_t) argc)
355 ThrowImportException(OptionError,"MissingArgument",option);
358 if ((LocaleCompare("help",option+1) == 0) ||
359 (LocaleCompare("-help",option+1) == 0))
360 return(ImportUsage());
363 Get user defaults from X resource database.
365 display=XOpenDisplay(server_name);
366 if (display == (Display *) NULL)
367 ThrowImportException(XServerError,"UnableToOpenXServer",
368 XDisplayName(server_name));
369 (void) XSetErrorHandler(XError);
370 resource_database=XGetResourceDatabase(display,GetClientName());
371 XGetImportInfo(&ximage_info);
372 XGetResourceInfo(image_info,resource_database,GetClientName(),
374 quantize_info=resource_info.quantize_info;
375 resource_value=XGetResourceInstance(resource_database,GetClientName(),
377 ximage_info.borders=IsMagickTrue(resource_value);
378 resource_value=XGetResourceInstance(resource_database,GetClientName(),
380 resource_info.delay=(unsigned int) StringToUnsignedLong(resource_value);
381 image_info->density=XGetResourceInstance(resource_database,GetClientName(),
382 "density",(char *) NULL);
383 resource_value=XGetResourceInstance(resource_database,GetClientName(),
385 ximage_info.descend=IsMagickTrue(resource_value);
386 resource_value=XGetResourceInstance(resource_database,GetClientName(),
388 ximage_info.frame=IsMagickTrue(resource_value);
389 resource_value=XGetResourceInstance(resource_database,GetClientName(),
391 image_info->interlace=UndefinedInterlace;
392 if (LocaleCompare("None",resource_value) == 0)
393 image_info->interlace=NoInterlace;
394 if (LocaleCompare("Line",resource_value) == 0)
395 image_info->interlace=LineInterlace;
396 if (LocaleCompare("Plane",resource_value) == 0)
397 image_info->interlace=PlaneInterlace;
398 if (LocaleCompare("Partition",resource_value) == 0)
399 image_info->interlace=PartitionInterlace;
400 if (image_info->interlace == UndefinedInterlace)
401 ThrowImportException(OptionError,"Unrecognized interlace type",
403 image_info->page=XGetResourceInstance(resource_database,GetClientName(),
404 "pageGeometry",(char *) NULL);
405 resource_value=XGetResourceInstance(resource_database,GetClientName(),
407 resource_info.pause=(unsigned int) StringToUnsignedLong(resource_value);
408 resource_value=XGetResourceInstance(resource_database,GetClientName(),
410 image_info->quality=StringToUnsignedLong(resource_value);
411 resource_value=XGetResourceInstance(resource_database,GetClientName(),
413 ximage_info.screen=IsMagickTrue(resource_value);
414 resource_value=XGetResourceInstance(resource_database,GetClientName(),
416 ximage_info.silent=IsMagickTrue(resource_value);
417 resource_value=XGetResourceInstance(resource_database,GetClientName(),
419 image_info->verbose=IsMagickTrue(resource_value);
420 resource_value=XGetResourceInstance(resource_database,GetClientName(),
422 quantize_info->dither=IsMagickTrue(resource_value);
425 filename=(char *) NULL;
427 Check command syntax.
429 for (i=1; i < (ssize_t) argc; i++)
432 if (LocaleCompare(option,"(") == 0)
434 FireImageStack(MagickFalse,MagickTrue,pend);
435 if (k == MaxImageStackDepth)
436 ThrowImportException(OptionError,"ParenthesisNestedTooDeeply",
441 if (LocaleCompare(option,")") == 0)
443 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
445 ThrowImportException(OptionError,"UnableToParseExpression",option);
449 if (IsCommandOption(option) == MagickFalse)
458 Read image from X server.
460 FireImageStack(MagickFalse,MagickFalse,pend);
462 if (target_window != (char *) NULL)
463 (void) CopyMagickString(image_info->filename,target_window,
465 for (scene=0; scene < (size_t) MagickMax(snapshots,1); scene++)
467 (void) sleep(resource_info.pause);
468 images=XImportImage(image_info,&ximage_info,exception);
469 status&=(images != (Image *) NULL) &&
470 (exception->severity < ErrorException);
471 if (images == (Image *) NULL)
473 (void) CopyMagickString(images->filename,filename,MaxTextExtent);
474 (void) CopyMagickString(images->magick,"PS",MaxTextExtent);
476 AppendImageStack(images);
480 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
485 if (LocaleCompare("adjoin",option+1) == 0)
487 if (LocaleCompare("annotate",option+1) == 0)
492 if (i == (ssize_t) (argc-1))
493 ThrowImportException(OptionError,"MissingArgument",option);
494 if (IsGeometry(argv[i]) == MagickFalse)
495 ThrowImportInvalidArgumentException(option,argv[i]);
496 if (i == (ssize_t) (argc-1))
497 ThrowImportException(OptionError,"MissingArgument",option);
501 ThrowImportException(OptionError,"UnrecognizedOption",option);
505 if (LocaleCompare("border",option+1) == 0)
507 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
508 ximage_info.borders=(*option == '-') ? MagickTrue : MagickFalse;
511 if (LocaleCompare("bordercolor",option+1) == 0)
516 if (i == (ssize_t) argc)
517 ThrowImportException(OptionError,"MissingArgument",option);
520 ThrowImportException(OptionError,"UnrecognizedOption",option);
524 if (LocaleCompare("cache",option+1) == 0)
529 if (i == (ssize_t) argc)
530 ThrowImportException(OptionError,"MissingArgument",option);
531 if (IsGeometry(argv[i]) == MagickFalse)
532 ThrowImportInvalidArgumentException(option,argv[i]);
535 if (LocaleCompare("channel",option+1) == 0)
543 if (i == (ssize_t) (argc-1))
544 ThrowImportException(OptionError,"MissingArgument",option);
545 channel=ParseChannelOption(argv[i]);
547 ThrowImportException(OptionError,"UnrecognizedChannelType",
551 if (LocaleCompare("colors",option+1) == 0)
553 quantize_info->number_colors=0;
557 if (i == (ssize_t) argc)
558 ThrowImportException(OptionError,"MissingArgument",option);
559 if (IsGeometry(argv[i]) == MagickFalse)
560 ThrowImportInvalidArgumentException(option,argv[i]);
561 quantize_info->number_colors=StringToUnsignedLong(argv[i]);
564 if (LocaleCompare("colorspace",option+1) == 0)
572 if (i == (ssize_t) argc)
573 ThrowImportException(OptionError,"MissingArgument",option);
574 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
577 ThrowImportException(OptionError,"UnrecognizedColorspace",
581 if (LocaleCompare("comment",option+1) == 0)
586 if (i == (ssize_t) argc)
587 ThrowImportException(OptionError,"MissingArgument",option);
588 status=SetImageOption(image_info,"comment",argv[i]);
589 if (status == MagickFalse)
590 ThrowImportException(OptionError,"UnrecognizedOption",argv[i]);
593 if (LocaleCompare("compress",option+1) == 0)
601 if (i == (ssize_t) argc)
602 ThrowImportException(OptionError,"MissingArgument",option);
603 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
606 ThrowImportException(OptionError,"UnrecognizedImageCompression",
610 if (LocaleCompare("concurrent",option+1) == 0)
612 if (LocaleCompare("crop",option+1) == 0)
617 if (i == (ssize_t) argc)
618 ThrowImportException(OptionError,"MissingArgument",option);
619 if (IsGeometry(argv[i]) == MagickFalse)
620 ThrowImportInvalidArgumentException(option,argv[i]);
623 ThrowImportException(OptionError,"UnrecognizedOption",option);
627 if (LocaleCompare("debug",option+1) == 0)
635 if (i == (ssize_t) argc)
636 ThrowImportException(OptionError,"MissingArgument",option);
637 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
639 ThrowImportException(OptionError,"UnrecognizedEventType",argv[i]);
640 (void) SetLogEventMask(argv[i]);
643 if (LocaleCompare("define",option+1) == 0)
646 if (i == (ssize_t) argc)
647 ThrowImportException(OptionError,"MissingArgument",option);
653 define=GetImageOption(image_info,argv[i]);
654 if (define == (char *) NULL)
655 ThrowImportException(OptionError,"NoSuchOption",argv[i]);
660 if (LocaleCompare("delay",option+1) == 0)
665 if (i == (ssize_t) argc)
666 ThrowImportException(OptionError,"MissingArgument",option);
667 if (IsGeometry(argv[i]) == MagickFalse)
668 ThrowImportInvalidArgumentException(option,argv[i]);
669 status=SetImageOption(image_info,"delay",argv[i]);
670 if (status == MagickFalse)
671 ThrowImportException(OptionError,"UnrecognizedOption",argv[i]);
674 if (LocaleCompare("density",option+1) == 0)
679 if (i == (ssize_t) argc)
680 ThrowImportException(OptionError,"MissingArgument",option);
681 if (IsGeometry(argv[i]) == MagickFalse)
682 ThrowImportInvalidArgumentException(option,argv[i]);
685 if (LocaleCompare("depth",option+1) == 0)
690 if (i == (ssize_t) argc)
691 ThrowImportException(OptionError,"MissingArgument",option);
692 if (IsGeometry(argv[i]) == MagickFalse)
693 ThrowImportInvalidArgumentException(option,argv[i]);
696 if (LocaleCompare("descend",option+1) == 0)
698 ximage_info.descend=(*option == '-') ? MagickTrue : MagickFalse;
701 if (LocaleCompare("display",option+1) == 0)
706 if (i == (ssize_t) argc)
707 ThrowImportException(OptionError,"MissingArgument",option);
710 if (LocaleCompare("dispose",option+1) == 0)
718 if (i == (ssize_t) argc)
719 ThrowImportException(OptionError,"MissingArgument",option);
720 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
722 ThrowImportException(OptionError,"UnrecognizedDisposeMethod",
726 if (LocaleCompare("dither",option+1) == 0)
731 quantize_info->dither=MagickFalse;
735 if (i == (ssize_t) argc)
736 ThrowImportException(OptionError,"MissingArgument",option);
737 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
739 ThrowImportException(OptionError,"UnrecognizedDitherMethod",
741 quantize_info->dither=MagickTrue;
742 quantize_info->dither_method=(DitherMethod) method;
745 if (LocaleCompare("duration",option+1) == 0)
750 if (i == (ssize_t) (argc-1))
751 ThrowImportException(OptionError,"MissingArgument",option);
752 if (IsGeometry(argv[i]) == MagickFalse)
753 ThrowImportInvalidArgumentException(option,argv[i]);
756 ThrowImportException(OptionError,"UnrecognizedOption",option);
760 if (LocaleCompare("encipher",option+1) == 0)
765 if (i == (ssize_t) (argc-1))
766 ThrowImportException(OptionError,"MissingArgument",option);
769 if (LocaleCompare("encoding",option+1) == 0)
774 if (i == (ssize_t) argc)
775 ThrowImportException(OptionError,"MissingArgument",option);
778 if (LocaleCompare("endian",option+1) == 0)
786 if (i == (ssize_t) argc)
787 ThrowImportException(OptionError,"MissingArgument",option);
788 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,
791 ThrowImportException(OptionError,"UnrecognizedEndianType",
795 ThrowImportException(OptionError,"UnrecognizedOption",option);
799 if (LocaleCompare("filter",option+1) == 0)
807 if (i == (ssize_t) (argc-1))
808 ThrowImportException(OptionError,"MissingArgument",option);
809 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
811 ThrowImportException(OptionError,"UnrecognizedImageFilter",
815 if (LocaleCompare("frame",option+1) == 0)
817 (void) CopyMagickString(argv[i]+1,"sans0",MaxTextExtent);
818 ximage_info.frame=(*option == '-') ? MagickTrue : MagickFalse;
821 if (LocaleCompare("format",option+1) == 0)
826 if (i == (ssize_t) (argc-1))
827 ThrowImportException(OptionError,"MissingArgument",option);
830 ThrowImportException(OptionError,"UnrecognizedOption",option);
834 if (LocaleCompare("geometry",option+1) == 0)
839 if (i == (ssize_t) argc)
840 ThrowImportException(OptionError,"MissingArgument",option);
841 if (IsGeometry(argv[i]) == MagickFalse)
842 ThrowImportInvalidArgumentException(option,argv[i]);
845 if (LocaleCompare("gravity",option+1) == 0)
853 if (i == (ssize_t) argc)
854 ThrowImportException(OptionError,"MissingArgument",option);
855 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
857 ThrowImportException(OptionError,"UnrecognizedGravityType",
861 ThrowImportException(OptionError,"UnrecognizedOption",option);
865 if (LocaleCompare("help",option+1) == 0)
867 ThrowImportException(OptionError,"UnrecognizedOption",option);
871 if (LocaleCompare("identify",option+1) == 0)
873 if (LocaleCompare("interlace",option+1) == 0)
881 if (i == (ssize_t) argc)
882 ThrowImportException(OptionError,"MissingArgument",option);
883 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
886 ThrowImportException(OptionError,"UnrecognizedInterlaceType",
890 if (LocaleCompare("interpolate",option+1) == 0)
898 if (i == (ssize_t) argc)
899 ThrowImportException(OptionError,"MissingArgument",option);
900 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
903 ThrowImportException(OptionError,"UnrecognizedInterpolateMethod",
907 ThrowImportException(OptionError,"UnrecognizedOption",option);
911 if (LocaleCompare("label",option+1) == 0)
916 if (i == (ssize_t) argc)
917 ThrowImportException(OptionError,"MissingArgument",option);
918 status=SetImageOption(image_info,"label",argv[i]);
919 if (status == MagickFalse)
920 ThrowImportException(OptionError,"UnrecognizedOption",argv[i]);
923 if (LocaleCompare("limit",option+1) == 0)
937 if (i == (ssize_t) argc)
938 ThrowImportException(OptionError,"MissingArgument",option);
939 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
942 ThrowImportException(OptionError,"UnrecognizedResourceType",
945 if (i == (ssize_t) argc)
946 ThrowImportException(OptionError,"MissingArgument",option);
947 value=InterpretLocaleValue(argv[i],&p);
949 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
950 ThrowImportInvalidArgumentException(option,argv[i]);
953 if (LocaleCompare("list",option+1) == 0)
961 if (i == (ssize_t) argc)
962 ThrowImportException(OptionError,"MissingArgument",option);
963 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
965 ThrowImportException(OptionError,"UnrecognizedListType",argv[i]);
966 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
969 return(status != 0 ? MagickFalse : MagickTrue);
971 if (LocaleCompare("log",option+1) == 0)
976 if ((i == (ssize_t) argc) || (strchr(argv[i],'%') == (char *) NULL))
977 ThrowImportException(OptionError,"MissingArgument",option);
980 ThrowImportException(OptionError,"UnrecognizedOption",option);
984 if (LocaleCompare("monitor",option+1) == 0)
986 if (LocaleCompare("monochrome",option+1) == 0)
990 quantize_info->number_colors=2;
991 quantize_info->colorspace=GRAYColorspace;
994 ThrowImportException(OptionError,"UnrecognizedOption",option);
998 if (LocaleCompare("negate",option+1) == 0)
1000 ThrowImportException(OptionError,"UnrecognizedOption",option);
1004 if (LocaleCompare("page",option+1) == 0)
1009 if (i == (ssize_t) argc)
1010 ThrowImportException(OptionError,"MissingArgument",option);
1011 status=SetImageOption(image_info,"page",argv[i]);
1012 if (status == MagickFalse)
1013 ThrowImportException(OptionError,"UnrecognizedOption",argv[i]);
1016 if (LocaleCompare("pause",option+1) == 0)
1018 resource_info.pause=0;
1022 if (i == (ssize_t) argc)
1023 ThrowImportException(OptionError,"MissingArgument",option);
1024 if (IsGeometry(argv[i]) == MagickFalse)
1025 ThrowImportInvalidArgumentException(option,argv[i]);
1026 resource_info.pause=(unsigned int) StringToUnsignedLong(argv[i]);
1029 if (LocaleCompare("ping",option+1) == 0)
1030 break; /* deprecated option */
1031 if (LocaleCompare("pointsize",option+1) == 0)
1036 if (i == (ssize_t) argc)
1037 ThrowImportException(OptionError,"MissingArgument",option);
1038 if (IsGeometry(argv[i]) == MagickFalse)
1039 ThrowImportInvalidArgumentException(option,argv[i]);
1042 ThrowImportException(OptionError,"UnrecognizedOption",option);
1046 if (LocaleCompare("quality",option+1) == 0)
1051 if (i == (ssize_t) argc)
1052 ThrowImportException(OptionError,"MissingArgument",option);
1053 if (IsGeometry(argv[i]) == MagickFalse)
1054 ThrowImportInvalidArgumentException(option,argv[i]);
1057 if (LocaleCompare("quantize",option+1) == 0)
1065 if (i == (ssize_t) (argc-1))
1066 ThrowImportException(OptionError,"MissingArgument",option);
1067 colorspace=ParseCommandOption(MagickColorspaceOptions,
1068 MagickFalse,argv[i]);
1070 ThrowImportException(OptionError,"UnrecognizedColorspace",
1074 if (LocaleCompare("quiet",option+1) == 0)
1076 ThrowImportException(OptionError,"UnrecognizedOption",option);
1080 if (LocaleCompare("regard-warnings",option+1) == 0)
1082 if (LocaleCompare("repage",option+1) == 0)
1087 if (i == (ssize_t) (argc-1))
1088 ThrowImportException(OptionError,"MissingArgument",option);
1089 if (IsGeometry(argv[i]) == MagickFalse)
1090 ThrowImportInvalidArgumentException(option,argv[i]);
1093 if (LocaleCompare("resize",option+1) == 0)
1098 if (i == (ssize_t) argc)
1099 ThrowImportException(OptionError,"MissingArgument",option);
1100 if (IsGeometry(argv[i]) == MagickFalse)
1101 ThrowImportInvalidArgumentException(option,argv[i]);
1104 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
1106 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
1109 if (LocaleCompare("rotate",option+1) == 0)
1112 if (i == (ssize_t) argc)
1113 ThrowImportException(OptionError,"MissingArgument",option);
1114 if (IsGeometry(argv[i]) == MagickFalse)
1115 ThrowImportInvalidArgumentException(option,argv[i]);
1118 ThrowImportException(OptionError,"UnrecognizedOption",option);
1122 if (LocaleCompare("sampling-factor",option+1) == 0)
1127 if (i == (ssize_t) argc)
1128 ThrowImportException(OptionError,"MissingArgument",option);
1129 if (IsGeometry(argv[i]) == MagickFalse)
1130 ThrowImportInvalidArgumentException(option,argv[i]);
1133 if (LocaleCompare("scene",option+1) == 0)
1138 if (i == (ssize_t) argc)
1139 ThrowImportException(OptionError,"MissingArgument",option);
1140 if (IsGeometry(argv[i]) == MagickFalse)
1141 ThrowImportInvalidArgumentException(option,argv[i]);
1144 if (LocaleCompare("set",option+1) == 0)
1147 if (i == (ssize_t) argc)
1148 ThrowImportException(OptionError,"MissingArgument",option);
1152 if (i == (ssize_t) argc)
1153 ThrowImportException(OptionError,"MissingArgument",option);
1156 if (LocaleCompare("screen",option+1) == 0)
1158 ximage_info.screen=(*option == '-') ? MagickTrue : MagickFalse;
1161 if (LocaleCompare("seed",option+1) == 0)
1166 if (i == (ssize_t) (argc-1))
1167 ThrowImportException(OptionError,"MissingArgument",option);
1168 if (IsGeometry(argv[i]) == MagickFalse)
1169 ThrowImportInvalidArgumentException(option,argv[i]);
1172 if (LocaleCompare("silent",option+1) == 0)
1174 ximage_info.silent=(*option == '-') ? MagickTrue : MagickFalse;
1177 if (LocaleCompare("snaps",option+1) == 0)
1179 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
1181 if (i == (ssize_t) argc)
1182 ThrowImportException(OptionError,"MissingArgument",option);
1183 if (IsGeometry(argv[i]) == MagickFalse)
1184 ThrowImportInvalidArgumentException(option,argv[i]);
1185 snapshots=(ssize_t) StringToLong(argv[i]);
1188 if (LocaleCompare("strip",option+1) == 0)
1190 if (LocaleCompare("support",option+1) == 0)
1192 i++; /* deprecated */
1195 if (LocaleCompare("synchronize",option+1) == 0)
1197 ThrowImportException(OptionError,"UnrecognizedOption",option);
1201 if (LocaleCompare("taint",option+1) == 0)
1203 if (LocaleCompare("thumbnail",option+1) == 0)
1208 if (i == (ssize_t) argc)
1209 ThrowImportException(OptionError,"MissingArgument",option);
1210 if (IsGeometry(argv[i]) == MagickFalse)
1211 ThrowImportInvalidArgumentException(option,argv[i]);
1214 if (LocaleCompare("transparent",option+1) == 0)
1217 if (i == (ssize_t) argc)
1218 ThrowImportException(OptionError,"MissingArgument",option);
1221 if (LocaleCompare("transparent-color",option+1) == 0)
1226 if (i == (ssize_t) (argc-1))
1227 ThrowImportException(OptionError,"MissingArgument",option);
1230 if (LocaleCompare("treedepth",option+1) == 0)
1232 quantize_info->tree_depth=0;
1236 if (i == (ssize_t) argc)
1237 ThrowImportException(OptionError,"MissingArgument",option);
1238 if (IsGeometry(argv[i]) == MagickFalse)
1239 ThrowImportInvalidArgumentException(option,argv[i]);
1240 quantize_info->tree_depth=StringToUnsignedLong(argv[i]);
1243 if (LocaleCompare("trim",option+1) == 0)
1245 if (LocaleCompare("type",option+1) == 0)
1253 if (i == (ssize_t) argc)
1254 ThrowImportException(OptionError,"MissingArgument",option);
1255 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
1257 ThrowImportException(OptionError,"UnrecognizedImageType",argv[i]);
1260 ThrowImportException(OptionError,"UnrecognizedOption",option);
1265 if (i == (ssize_t) argc)
1266 ThrowImportException(OptionError,"MissingArgument",option);
1267 (void) CloneString(&target_window,argv[i]);
1272 if (LocaleCompare("verbose",option+1) == 0)
1274 if ((LocaleCompare("version",option+1) == 0) ||
1275 (LocaleCompare("-version",option+1) == 0))
1277 (void) FormatLocaleFile(stdout,"Version: %s\n",
1278 GetMagickVersion((size_t *) NULL));
1279 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
1280 GetMagickCopyright());
1281 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
1282 GetMagickFeatures());
1285 ThrowImportException(OptionError,"UnrecognizedOption",option);
1290 ThrowImportException(OptionError,"UnrecognizedOption",option);
1292 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
1293 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
1294 if (fire != MagickFalse)
1295 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
1298 ThrowImportException(OptionError,"UnbalancedParenthesis",argv[i]);
1299 if (i-- != (ssize_t) argc)
1300 ThrowImportException(OptionError,"MissingAnImageFilename",argv[i]);
1301 if (image == (Image *) NULL)
1302 ThrowImportException(OptionError,"MissingAnImageFilename",argv[argc-1]);
1303 FinalizeImageSettings(image_info,image,MagickTrue);
1304 status&=WriteImages(image_info,image,filename,exception);
1306 return(status != 0 ? MagickTrue : MagickFalse);
1310 (void) ThrowMagickException(exception,GetMagickModule(),MissingDelegateError,
1311 "DelegateLibrarySupportNotBuiltIn","`%s' (X11)",image_info->filename);
1312 return(ImportUsage());