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-2014 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.
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 seconds 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 "-support factor resize support: > 1.0 is blurry, < 1.0 is sharp",
176 "-synchronize synchronize image to storage device",
177 "-taint declare the image as modified",
178 "-transparent-color color",
179 " transparent color",
180 "-treedepth value color tree depth",
181 "-verbose print detailed information about the image",
182 "-virtual-pixel method",
183 " Constant, Edge, Mirror, or Tile",
184 "-window id select window with this id or name",
188 ListMagickVersion(stdout);
189 (void) printf("Usage: %s [options ...] [ file ]\n",
191 (void) printf("\nImage Settings:\n");
192 for (p=settings; *p != (char *) NULL; p++)
193 (void) printf(" %s\n",*p);
194 (void) printf("\nImage Operators:\n");
195 for (p=operators; *p != (char *) NULL; p++)
196 (void) printf(" %s\n",*p);
197 (void) printf("\nMiscellaneous Options:\n");
198 for (p=miscellaneous; *p != (char *) NULL; p++)
199 (void) printf(" %s\n",*p);
201 "\nBy default, 'file' is written in the MIFF image format. To\n");
203 "specify a particular image format, precede the filename with an image\n");
205 "format name and a colon (i.e. ps:image) or specify the image type as\n");
207 "the filename suffix (i.e. image.ps). Specify 'file' as '-' for\n");
208 (void) printf("standard input or output.\n");
212 static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
219 WandExport MagickBooleanType ImportImageCommand(ImageInfo *image_info,
220 int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
222 #if defined(MAGICKCORE_X11_DELEGATE)
223 #define DestroyImport() \
225 XDestroyResourceInfo(&resource_info); \
226 if (display != (Display *) NULL) \
228 XCloseDisplay(display); \
229 display=(Display *) NULL; \
231 DestroyImageStack(); \
232 if (target_window != (char *) NULL) \
233 target_window=DestroyString(target_window); \
234 for (i=0; i < (ssize_t) argc; i++) \
235 argv[i]=DestroyString(argv[i]); \
236 argv=(char **) RelinquishMagickMemory(argv); \
238 #define ThrowImportException(asperity,tag,option) \
240 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
243 return(MagickFalse); \
245 #define ThrowImportInvalidArgumentException(option,argument) \
247 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
248 "InvalidArgument","'%s': %s",option,argument); \
250 return(MagickFalse); \
267 image_stack[MaxImageStackDepth+1];
300 assert(image_info != (ImageInfo *) NULL);
301 assert(image_info->signature == MagickSignature);
302 if (image_info->debug != MagickFalse)
303 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
304 assert(exception != (ExceptionInfo *) NULL);
308 if ((LocaleCompare("version",option+1) == 0) ||
309 (LocaleCompare("-version",option+1) == 0))
311 ListMagickVersion(stdout);
315 display=(Display *) NULL;
319 option=(char *) NULL;
321 resource_database=(XrmDatabase) NULL;
322 respect_parenthesis=MagickFalse;
323 (void) ResetMagickMemory(&resource_info,0,sizeof(resource_info));
324 server_name=(char *) NULL;
327 target_window=(char *) NULL;
329 Check for server name specified on the command line.
331 ReadCommandlLine(argc,&argv);
332 status=ExpandFilenames(&argc,&argv);
333 if (status == MagickFalse)
334 ThrowImportException(ResourceLimitError,"MemoryAllocationFailed",
335 GetExceptionMessage(errno));
336 for (i=1; i < (ssize_t) argc; i++)
339 Check command line for server name.
342 if (LocaleCompare("display",option+1) == 0)
345 User specified server name.
348 if (i == (ssize_t) argc)
349 ThrowImportException(OptionError,"MissingArgument",option);
352 if ((LocaleCompare("help",option+1) == 0) ||
353 (LocaleCompare("-help",option+1) == 0))
354 return(ImportUsage());
357 Get user defaults from X resource database.
359 display=XOpenDisplay(server_name);
360 if (display == (Display *) NULL)
361 ThrowImportException(XServerError,"UnableToOpenXServer",
362 XDisplayName(server_name));
363 (void) XSetErrorHandler(XError);
364 resource_database=XGetResourceDatabase(display,GetClientName());
365 XGetImportInfo(&ximage_info);
366 XGetResourceInfo(image_info,resource_database,GetClientName(),
368 quantize_info=resource_info.quantize_info;
369 resource_value=XGetResourceInstance(resource_database,GetClientName(),
371 ximage_info.borders=IsStringTrue(resource_value);
372 resource_value=XGetResourceInstance(resource_database,GetClientName(),
374 resource_info.delay=(unsigned int) StringToUnsignedLong(resource_value);
375 image_info->density=XGetResourceInstance(resource_database,GetClientName(),
376 "density",(char *) NULL);
377 resource_value=XGetResourceInstance(resource_database,GetClientName(),
379 ximage_info.descend=IsStringTrue(resource_value);
380 resource_value=XGetResourceInstance(resource_database,GetClientName(),
382 ximage_info.frame=IsStringTrue(resource_value);
383 resource_value=XGetResourceInstance(resource_database,GetClientName(),
385 image_info->interlace=UndefinedInterlace;
386 if (LocaleCompare("None",resource_value) == 0)
387 image_info->interlace=NoInterlace;
388 if (LocaleCompare("Line",resource_value) == 0)
389 image_info->interlace=LineInterlace;
390 if (LocaleCompare("Plane",resource_value) == 0)
391 image_info->interlace=PlaneInterlace;
392 if (LocaleCompare("Partition",resource_value) == 0)
393 image_info->interlace=PartitionInterlace;
394 if (image_info->interlace == UndefinedInterlace)
395 ThrowImportException(OptionError,"Unrecognized interlace type",
397 image_info->page=XGetResourceInstance(resource_database,GetClientName(),
398 "pageGeometry",(char *) NULL);
399 resource_value=XGetResourceInstance(resource_database,GetClientName(),
401 resource_info.pause=(unsigned int) StringToUnsignedLong(resource_value);
402 resource_value=XGetResourceInstance(resource_database,GetClientName(),
404 image_info->quality=StringToUnsignedLong(resource_value);
405 resource_value=XGetResourceInstance(resource_database,GetClientName(),
407 ximage_info.screen=IsStringTrue(resource_value);
408 resource_value=XGetResourceInstance(resource_database,GetClientName(),
410 ximage_info.silent=IsStringTrue(resource_value);
411 resource_value=XGetResourceInstance(resource_database,GetClientName(),
413 image_info->verbose=IsStringTrue(resource_value);
414 resource_value=XGetResourceInstance(resource_database,GetClientName(),
416 quantize_info->dither_method=IsStringTrue(resource_value) != MagickFalse ?
417 RiemersmaDitherMethod : NoDitherMethod;
420 filename=(char *) NULL;
422 Check command syntax.
424 for (i=1; i < (ssize_t) argc; i++)
427 if (LocaleCompare(option,"(") == 0)
429 FireImageStack(MagickFalse,MagickTrue,pend);
430 if (k == MaxImageStackDepth)
431 ThrowImportException(OptionError,"ParenthesisNestedTooDeeply",
436 if (LocaleCompare(option,")") == 0)
438 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
440 ThrowImportException(OptionError,"UnableToParseExpression",option);
444 if (IsCommandOption(option) == MagickFalse)
453 Read image from X server.
455 FireImageStack(MagickFalse,MagickFalse,pend);
457 if (target_window != (char *) NULL)
458 (void) CopyMagickString(image_info->filename,target_window,
460 for (scene=0; scene < (size_t) MagickMax(snapshots,1); scene++)
462 (void) sleep(resource_info.pause);
463 images=XImportImage(image_info,&ximage_info,exception);
464 status&=(images != (Image *) NULL) &&
465 (exception->severity < ErrorException);
466 if (images == (Image *) NULL)
468 (void) CopyMagickString(images->filename,filename,MaxTextExtent);
469 (void) CopyMagickString(images->magick,"PS",MaxTextExtent);
471 AppendImageStack(images);
475 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
480 if (LocaleCompare("adjoin",option+1) == 0)
482 if (LocaleCompare("annotate",option+1) == 0)
487 if (i == (ssize_t) (argc-1))
488 ThrowImportException(OptionError,"MissingArgument",option);
489 if (IsGeometry(argv[i]) == MagickFalse)
490 ThrowImportInvalidArgumentException(option,argv[i]);
491 if (i == (ssize_t) (argc-1))
492 ThrowImportException(OptionError,"MissingArgument",option);
496 ThrowImportException(OptionError,"UnrecognizedOption",option);
500 if (LocaleCompare("border",option+1) == 0)
502 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
503 ximage_info.borders=(*option == '-') ? MagickTrue : MagickFalse;
506 if (LocaleCompare("bordercolor",option+1) == 0)
511 if (i == (ssize_t) argc)
512 ThrowImportException(OptionError,"MissingArgument",option);
515 ThrowImportException(OptionError,"UnrecognizedOption",option);
519 if (LocaleCompare("cache",option+1) == 0)
524 if (i == (ssize_t) argc)
525 ThrowImportException(OptionError,"MissingArgument",option);
526 if (IsGeometry(argv[i]) == MagickFalse)
527 ThrowImportInvalidArgumentException(option,argv[i]);
530 if (LocaleCompare("channel",option+1) == 0)
538 if (i == (ssize_t) (argc-1))
539 ThrowImportException(OptionError,"MissingArgument",option);
540 channel=ParseChannelOption(argv[i]);
542 ThrowImportException(OptionError,"UnrecognizedChannelType",
546 if (LocaleCompare("colors",option+1) == 0)
548 quantize_info->number_colors=0;
552 if (i == (ssize_t) argc)
553 ThrowImportException(OptionError,"MissingArgument",option);
554 if (IsGeometry(argv[i]) == MagickFalse)
555 ThrowImportInvalidArgumentException(option,argv[i]);
556 quantize_info->number_colors=StringToUnsignedLong(argv[i]);
559 if (LocaleCompare("colorspace",option+1) == 0)
567 if (i == (ssize_t) argc)
568 ThrowImportException(OptionError,"MissingArgument",option);
569 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
572 ThrowImportException(OptionError,"UnrecognizedColorspace",
576 if (LocaleCompare("comment",option+1) == 0)
581 if (i == (ssize_t) argc)
582 ThrowImportException(OptionError,"MissingArgument",option);
583 status=SetImageOption(image_info,"comment",argv[i]);
584 if (status == MagickFalse)
585 ThrowImportException(OptionError,"UnrecognizedOption",argv[i]);
588 if (LocaleCompare("compress",option+1) == 0)
596 if (i == (ssize_t) argc)
597 ThrowImportException(OptionError,"MissingArgument",option);
598 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
601 ThrowImportException(OptionError,"UnrecognizedImageCompression",
605 if (LocaleCompare("concurrent",option+1) == 0)
607 if (LocaleCompare("crop",option+1) == 0)
612 if (i == (ssize_t) argc)
613 ThrowImportException(OptionError,"MissingArgument",option);
614 if (IsGeometry(argv[i]) == MagickFalse)
615 ThrowImportInvalidArgumentException(option,argv[i]);
618 ThrowImportException(OptionError,"UnrecognizedOption",option);
622 if (LocaleCompare("debug",option+1) == 0)
630 if (i == (ssize_t) argc)
631 ThrowImportException(OptionError,"MissingArgument",option);
632 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
634 ThrowImportException(OptionError,"UnrecognizedEventType",argv[i]);
635 (void) SetLogEventMask(argv[i]);
638 if (LocaleCompare("define",option+1) == 0)
641 if (i == (ssize_t) argc)
642 ThrowImportException(OptionError,"MissingArgument",option);
648 define=GetImageOption(image_info,argv[i]);
649 if (define == (char *) NULL)
650 ThrowImportException(OptionError,"NoSuchOption",argv[i]);
655 if (LocaleCompare("delay",option+1) == 0)
660 if (i == (ssize_t) argc)
661 ThrowImportException(OptionError,"MissingArgument",option);
662 if (IsGeometry(argv[i]) == MagickFalse)
663 ThrowImportInvalidArgumentException(option,argv[i]);
664 status=SetImageOption(image_info,"delay",argv[i]);
665 if (status == MagickFalse)
666 ThrowImportException(OptionError,"UnrecognizedOption",argv[i]);
669 if (LocaleCompare("density",option+1) == 0)
674 if (i == (ssize_t) argc)
675 ThrowImportException(OptionError,"MissingArgument",option);
676 if (IsGeometry(argv[i]) == MagickFalse)
677 ThrowImportInvalidArgumentException(option,argv[i]);
680 if (LocaleCompare("depth",option+1) == 0)
685 if (i == (ssize_t) argc)
686 ThrowImportException(OptionError,"MissingArgument",option);
687 if (IsGeometry(argv[i]) == MagickFalse)
688 ThrowImportInvalidArgumentException(option,argv[i]);
691 if (LocaleCompare("descend",option+1) == 0)
693 ximage_info.descend=(*option == '-') ? MagickTrue : MagickFalse;
696 if (LocaleCompare("display",option+1) == 0)
701 if (i == (ssize_t) argc)
702 ThrowImportException(OptionError,"MissingArgument",option);
705 if (LocaleCompare("dispose",option+1) == 0)
713 if (i == (ssize_t) argc)
714 ThrowImportException(OptionError,"MissingArgument",option);
715 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
717 ThrowImportException(OptionError,"UnrecognizedDisposeMethod",
721 if (LocaleCompare("dither",option+1) == 0)
726 quantize_info->dither_method=NoDitherMethod;
730 if (i == (ssize_t) argc)
731 ThrowImportException(OptionError,"MissingArgument",option);
732 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
734 ThrowImportException(OptionError,"UnrecognizedDitherMethod",
736 quantize_info->dither_method=(DitherMethod) method;
739 if (LocaleCompare("duration",option+1) == 0)
744 if (i == (ssize_t) (argc-1))
745 ThrowImportException(OptionError,"MissingArgument",option);
746 if (IsGeometry(argv[i]) == MagickFalse)
747 ThrowImportInvalidArgumentException(option,argv[i]);
750 ThrowImportException(OptionError,"UnrecognizedOption",option);
754 if (LocaleCompare("encipher",option+1) == 0)
759 if (i == (ssize_t) (argc-1))
760 ThrowImportException(OptionError,"MissingArgument",option);
763 if (LocaleCompare("encoding",option+1) == 0)
768 if (i == (ssize_t) argc)
769 ThrowImportException(OptionError,"MissingArgument",option);
772 if (LocaleCompare("endian",option+1) == 0)
780 if (i == (ssize_t) argc)
781 ThrowImportException(OptionError,"MissingArgument",option);
782 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,
785 ThrowImportException(OptionError,"UnrecognizedEndianType",
789 ThrowImportException(OptionError,"UnrecognizedOption",option);
793 if (LocaleCompare("filter",option+1) == 0)
801 if (i == (ssize_t) (argc-1))
802 ThrowImportException(OptionError,"MissingArgument",option);
803 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
805 ThrowImportException(OptionError,"UnrecognizedImageFilter",
809 if (LocaleCompare("frame",option+1) == 0)
811 (void) CopyMagickString(argv[i]+1,"sans0",MaxTextExtent);
812 ximage_info.frame=(*option == '-') ? MagickTrue : MagickFalse;
815 if (LocaleCompare("format",option+1) == 0)
820 if (i == (ssize_t) (argc-1))
821 ThrowImportException(OptionError,"MissingArgument",option);
824 ThrowImportException(OptionError,"UnrecognizedOption",option);
828 if (LocaleCompare("geometry",option+1) == 0)
833 if (i == (ssize_t) argc)
834 ThrowImportException(OptionError,"MissingArgument",option);
835 if (IsGeometry(argv[i]) == MagickFalse)
836 ThrowImportInvalidArgumentException(option,argv[i]);
839 if (LocaleCompare("gravity",option+1) == 0)
847 if (i == (ssize_t) argc)
848 ThrowImportException(OptionError,"MissingArgument",option);
849 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
851 ThrowImportException(OptionError,"UnrecognizedGravityType",
855 ThrowImportException(OptionError,"UnrecognizedOption",option);
859 if (LocaleCompare("help",option+1) == 0)
861 ThrowImportException(OptionError,"UnrecognizedOption",option);
865 if (LocaleCompare("identify",option+1) == 0)
867 if (LocaleCompare("interlace",option+1) == 0)
875 if (i == (ssize_t) argc)
876 ThrowImportException(OptionError,"MissingArgument",option);
877 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
880 ThrowImportException(OptionError,"UnrecognizedInterlaceType",
884 if (LocaleCompare("interpolate",option+1) == 0)
892 if (i == (ssize_t) argc)
893 ThrowImportException(OptionError,"MissingArgument",option);
894 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
897 ThrowImportException(OptionError,"UnrecognizedInterpolateMethod",
901 ThrowImportException(OptionError,"UnrecognizedOption",option);
905 if (LocaleCompare("label",option+1) == 0)
910 if (i == (ssize_t) argc)
911 ThrowImportException(OptionError,"MissingArgument",option);
912 status=SetImageOption(image_info,"label",argv[i]);
913 if (status == MagickFalse)
914 ThrowImportException(OptionError,"UnrecognizedOption",argv[i]);
917 if (LocaleCompare("limit",option+1) == 0)
931 if (i == (ssize_t) argc)
932 ThrowImportException(OptionError,"MissingArgument",option);
933 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
936 ThrowImportException(OptionError,"UnrecognizedResourceType",
939 if (i == (ssize_t) argc)
940 ThrowImportException(OptionError,"MissingArgument",option);
941 value=StringToDouble(argv[i],&p);
943 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
944 ThrowImportInvalidArgumentException(option,argv[i]);
947 if (LocaleCompare("list",option+1) == 0)
955 if (i == (ssize_t) argc)
956 ThrowImportException(OptionError,"MissingArgument",option);
957 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
959 ThrowImportException(OptionError,"UnrecognizedListType",argv[i]);
960 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
963 return(status != 0 ? MagickFalse : MagickTrue);
965 if (LocaleCompare("log",option+1) == 0)
970 if ((i == (ssize_t) argc) || (strchr(argv[i],'%') == (char *) NULL))
971 ThrowImportException(OptionError,"MissingArgument",option);
974 ThrowImportException(OptionError,"UnrecognizedOption",option);
978 if (LocaleCompare("monitor",option+1) == 0)
980 if (LocaleCompare("monochrome",option+1) == 0)
984 quantize_info->number_colors=2;
985 quantize_info->colorspace=GRAYColorspace;
988 ThrowImportException(OptionError,"UnrecognizedOption",option);
992 if (LocaleCompare("negate",option+1) == 0)
994 ThrowImportException(OptionError,"UnrecognizedOption",option);
998 if (LocaleCompare("page",option+1) == 0)
1003 if (i == (ssize_t) argc)
1004 ThrowImportException(OptionError,"MissingArgument",option);
1005 status=SetImageOption(image_info,"page",argv[i]);
1006 if (status == MagickFalse)
1007 ThrowImportException(OptionError,"UnrecognizedOption",argv[i]);
1010 if (LocaleCompare("pause",option+1) == 0)
1012 resource_info.pause=0;
1016 if (i == (ssize_t) argc)
1017 ThrowImportException(OptionError,"MissingArgument",option);
1018 if (IsGeometry(argv[i]) == MagickFalse)
1019 ThrowImportInvalidArgumentException(option,argv[i]);
1020 resource_info.pause=(unsigned int) StringToUnsignedLong(argv[i]);
1023 if (LocaleCompare("ping",option+1) == 0)
1024 break; /* deprecated option */
1025 if (LocaleCompare("pointsize",option+1) == 0)
1030 if (i == (ssize_t) argc)
1031 ThrowImportException(OptionError,"MissingArgument",option);
1032 if (IsGeometry(argv[i]) == MagickFalse)
1033 ThrowImportInvalidArgumentException(option,argv[i]);
1036 ThrowImportException(OptionError,"UnrecognizedOption",option);
1040 if (LocaleCompare("quality",option+1) == 0)
1045 if (i == (ssize_t) argc)
1046 ThrowImportException(OptionError,"MissingArgument",option);
1047 if (IsGeometry(argv[i]) == MagickFalse)
1048 ThrowImportInvalidArgumentException(option,argv[i]);
1051 if (LocaleCompare("quantize",option+1) == 0)
1059 if (i == (ssize_t) (argc-1))
1060 ThrowImportException(OptionError,"MissingArgument",option);
1061 colorspace=ParseCommandOption(MagickColorspaceOptions,
1062 MagickFalse,argv[i]);
1064 ThrowImportException(OptionError,"UnrecognizedColorspace",
1068 if (LocaleCompare("quiet",option+1) == 0)
1070 ThrowImportException(OptionError,"UnrecognizedOption",option);
1074 if (LocaleCompare("regard-warnings",option+1) == 0)
1076 if (LocaleCompare("repage",option+1) == 0)
1081 if (i == (ssize_t) (argc-1))
1082 ThrowImportException(OptionError,"MissingArgument",option);
1083 if (IsGeometry(argv[i]) == MagickFalse)
1084 ThrowImportInvalidArgumentException(option,argv[i]);
1087 if (LocaleCompare("resize",option+1) == 0)
1092 if (i == (ssize_t) argc)
1093 ThrowImportException(OptionError,"MissingArgument",option);
1094 if (IsGeometry(argv[i]) == MagickFalse)
1095 ThrowImportInvalidArgumentException(option,argv[i]);
1098 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
1100 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
1103 if (LocaleCompare("rotate",option+1) == 0)
1106 if (i == (ssize_t) argc)
1107 ThrowImportException(OptionError,"MissingArgument",option);
1108 if (IsGeometry(argv[i]) == MagickFalse)
1109 ThrowImportInvalidArgumentException(option,argv[i]);
1112 ThrowImportException(OptionError,"UnrecognizedOption",option);
1116 if (LocaleCompare("sampling-factor",option+1) == 0)
1121 if (i == (ssize_t) argc)
1122 ThrowImportException(OptionError,"MissingArgument",option);
1123 if (IsGeometry(argv[i]) == MagickFalse)
1124 ThrowImportInvalidArgumentException(option,argv[i]);
1127 if (LocaleCompare("scene",option+1) == 0)
1132 if (i == (ssize_t) argc)
1133 ThrowImportException(OptionError,"MissingArgument",option);
1134 if (IsGeometry(argv[i]) == MagickFalse)
1135 ThrowImportInvalidArgumentException(option,argv[i]);
1138 if (LocaleCompare("set",option+1) == 0)
1141 if (i == (ssize_t) argc)
1142 ThrowImportException(OptionError,"MissingArgument",option);
1146 if (i == (ssize_t) argc)
1147 ThrowImportException(OptionError,"MissingArgument",option);
1150 if (LocaleCompare("screen",option+1) == 0)
1152 ximage_info.screen=(*option == '-') ? MagickTrue : MagickFalse;
1155 if (LocaleCompare("seed",option+1) == 0)
1160 if (i == (ssize_t) (argc-1))
1161 ThrowImportException(OptionError,"MissingArgument",option);
1162 if (IsGeometry(argv[i]) == MagickFalse)
1163 ThrowImportInvalidArgumentException(option,argv[i]);
1166 if (LocaleCompare("silent",option+1) == 0)
1168 ximage_info.silent=(*option == '-') ? MagickTrue : MagickFalse;
1171 if (LocaleCompare("snaps",option+1) == 0)
1173 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
1175 if (i == (ssize_t) argc)
1176 ThrowImportException(OptionError,"MissingArgument",option);
1177 if (IsGeometry(argv[i]) == MagickFalse)
1178 ThrowImportInvalidArgumentException(option,argv[i]);
1179 snapshots=(ssize_t) StringToLong(argv[i]);
1182 if (LocaleCompare("strip",option+1) == 0)
1184 if (LocaleCompare("support",option+1) == 0)
1186 i++; /* deprecated */
1189 if (LocaleCompare("synchronize",option+1) == 0)
1191 ThrowImportException(OptionError,"UnrecognizedOption",option);
1195 if (LocaleCompare("taint",option+1) == 0)
1197 if (LocaleCompare("thumbnail",option+1) == 0)
1202 if (i == (ssize_t) argc)
1203 ThrowImportException(OptionError,"MissingArgument",option);
1204 if (IsGeometry(argv[i]) == MagickFalse)
1205 ThrowImportInvalidArgumentException(option,argv[i]);
1208 if (LocaleCompare("transparent",option+1) == 0)
1211 if (i == (ssize_t) argc)
1212 ThrowImportException(OptionError,"MissingArgument",option);
1215 if (LocaleCompare("transparent-color",option+1) == 0)
1220 if (i == (ssize_t) (argc-1))
1221 ThrowImportException(OptionError,"MissingArgument",option);
1224 if (LocaleCompare("treedepth",option+1) == 0)
1226 quantize_info->tree_depth=0;
1230 if (i == (ssize_t) argc)
1231 ThrowImportException(OptionError,"MissingArgument",option);
1232 if (IsGeometry(argv[i]) == MagickFalse)
1233 ThrowImportInvalidArgumentException(option,argv[i]);
1234 quantize_info->tree_depth=StringToUnsignedLong(argv[i]);
1237 if (LocaleCompare("trim",option+1) == 0)
1239 if (LocaleCompare("type",option+1) == 0)
1247 if (i == (ssize_t) argc)
1248 ThrowImportException(OptionError,"MissingArgument",option);
1249 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
1251 ThrowImportException(OptionError,"UnrecognizedImageType",argv[i]);
1254 ThrowImportException(OptionError,"UnrecognizedOption",option);
1259 if (i == (ssize_t) argc)
1260 ThrowImportException(OptionError,"MissingArgument",option);
1261 (void) CloneString(&target_window,argv[i]);
1266 if (LocaleCompare("verbose",option+1) == 0)
1268 if ((LocaleCompare("version",option+1) == 0) ||
1269 (LocaleCompare("-version",option+1) == 0))
1271 ListMagickVersion(stdout);
1274 ThrowImportException(OptionError,"UnrecognizedOption",option);
1279 ThrowImportException(OptionError,"UnrecognizedOption",option);
1281 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
1282 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
1283 if (fire != MagickFalse)
1284 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
1287 ThrowImportException(OptionError,"UnbalancedParenthesis",argv[i]);
1288 if (i-- != (ssize_t) argc)
1289 ThrowImportException(OptionError,"MissingAnImageFilename",argv[i]);
1290 if (image == (Image *) NULL)
1291 ThrowImportException(OptionError,"MissingAnImageFilename",argv[argc-1]);
1292 FinalizeImageSettings(image_info,image,MagickTrue);
1293 status&=WriteImages(image_info,image,filename,exception);
1295 return(status != 0 ? MagickTrue : MagickFalse);
1299 (void) ThrowMagickException(exception,GetMagickModule(),MissingDelegateError,
1300 "DelegateLibrarySupportNotBuiltIn","'%s' (X11)",image_info->filename);
1301 return(ImportUsage());