]> granicus.if.org Git - imagemagick/blob - MagickWand/mogrify.c
(no commit message)
[imagemagick] / MagickWand / mogrify.c
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %                                                                             %
4 %                                                                             %
5 %                                                                             %
6 %              M   M   OOO   GGGGG  RRRR   IIIII  FFFFF  Y   Y                %
7 %              MM MM  O   O  G      R   R    I    F       Y Y                 %
8 %              M M M  O   O  G GGG  RRRR     I    FFF      Y                  %
9 %              M   M  O   O  G   G  R R      I    F        Y                  %
10 %              M   M   OOO   GGGG   R  R   IIIII  F        Y                  %
11 %                                                                             %
12 %                                                                             %
13 %                         MagickWand Module Methods                           %
14 %                                                                             %
15 %                              Software Design                                %
16 %                                John Cristy                                  %
17 %                                March 2000                                   %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization      %
21 %  dedicated to making software imaging solutions freely available.           %
22 %                                                                             %
23 %  You may not use this file except in compliance with the License.  You may  %
24 %  obtain a copy of the License at                                            %
25 %                                                                             %
26 %    http://www.imagemagick.org/script/license.php                            %
27 %                                                                             %
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.                                             %
33 %                                                                             %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %
36 %  Use the mogrify program to resize an image, blur, crop, despeckle, dither,
37 %  draw on, flip, join, re-sample, and much more. This tool is similiar to
38 %  convert except that the original image file is overwritten (unless you
39 %  change the file suffix with the -format option) with any changes you
40 %  request.
41 %
42 */
43 \f
44 /*
45   Include declarations.
46 */
47 #include "MagickWand/studio.h"
48 #include "MagickWand/MagickWand.h"
49 #include "MagickWand/mogrify-private.h"
50 #undef DegreesToRadians
51 #undef RadiansToDegrees
52 #include "MagickCore/image-private.h"
53 #include "MagickCore/monitor-private.h"
54 #include "MagickCore/string-private.h"
55 #include "MagickCore/thread-private.h"
56 #include "MagickCore/utility-private.h"
57 \f
58 /*
59  Constant declaration.
60 */
61 static const char
62   MogrifyBackgroundColor[] = "#ffffff",  /* white */
63   MogrifyBorderColor[] = "#dfdfdf",  /* gray */
64   MogrifyMatteColor[] = "#bdbdbd";  /* gray */
65 \f
66 /*
67   Define declarations.
68 */
69 #define UndefinedCompressionQuality  0UL
70 \f
71 /*
72 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 %                                                                             %
74 %                                                                             %
75 %                                                                             %
76 %     M a g i c k C o m m a n d G e n e s i s                                 %
77 %                                                                             %
78 %                                                                             %
79 %                                                                             %
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 %
82 %  MagickCommandGenesis() applies image processing options to an image as
83 %  prescribed by command line options.
84 %
85 %  The format of the MagickCommandGenesis method is:
86 %
87 %      MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
88 %        MagickCommand command,int argc,char **argv,char **metadata,
89 %        ExceptionInfo *exception)
90 %
91 %  A description of each parameter follows:
92 %
93 %    o image_info: the image info.
94 %
95 %    o command: Choose from ConvertImageCommand, IdentifyImageCommand,
96 %      MogrifyImageCommand, CompositeImageCommand, CompareImagesCommand,
97 %      ConjureImageCommand, StreamImageCommand, ImportImageCommand,
98 %      DisplayImageCommand, or AnimateImageCommand.
99 %
100 %    o argc: Specifies a pointer to an integer describing the number of
101 %      elements in the argument vector.
102 %
103 %    o argv: Specifies a pointer to a text array containing the command line
104 %      arguments.
105 %
106 %    o metadata: any metadata is returned here.
107 %
108 %    o exception: return any errors or warnings in this structure.
109 %
110 */
111
112 static inline double MagickMin(const double x,const double y)
113 {
114   if (x < y)
115     return(x);
116   return(y);
117 }
118
119 WandExport MagickBooleanType MagickCommandGenesis(ImageInfo *image_info,
120   MagickCommand command,int argc,char **argv,char **metadata,
121   ExceptionInfo *exception)
122 {
123   char
124     *option;
125
126   double
127     duration,
128     serial;
129
130   MagickBooleanType
131     concurrent,
132     regard_warnings,
133     status;
134
135   register ssize_t
136     i;
137
138   size_t
139     iterations,
140     n,
141     number_threads;
142
143   (void) setlocale(LC_ALL,"");
144   (void) setlocale(LC_NUMERIC,"C");
145   concurrent=MagickFalse;
146   duration=(-1.0);
147   iterations=1;
148   status=MagickFalse;
149   regard_warnings=MagickFalse;
150   for (i=1; i < (ssize_t) (argc-1); i++)
151   {
152     option=argv[i];
153     if ((strlen(option) == 1) || ((*option != '-') && (*option != '+')))
154       continue;
155     if (LocaleCompare("bench",option+1) == 0)
156       iterations=StringToUnsignedLong(argv[++i]);
157     if (LocaleCompare("concurrent",option+1) == 0)
158       concurrent=MagickTrue;
159     if (LocaleCompare("debug",option+1) == 0)
160       (void) SetLogEventMask(argv[++i]);
161     if (LocaleCompare("duration",option+1) == 0)
162       duration=StringToDouble(argv[++i],(char **) NULL);
163     if (LocaleCompare("regard-warnings",option+1) == 0)
164       regard_warnings=MagickTrue;
165   }
166   if (iterations == 1)
167     {
168       status=command(image_info,argc,argv,metadata,exception);
169       if (exception->severity != UndefinedException)
170         {
171           if ((exception->severity > ErrorException) ||
172               (regard_warnings != MagickFalse))
173             status=MagickTrue;
174           CatchException(exception);
175         }
176         if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
177           {
178             (void) fputs(*metadata,stdout);
179             (void) fputc('\n',stdout);
180             *metadata=DestroyString(*metadata);
181           }
182       return(status);
183     }
184   number_threads=GetOpenMPMaximumThreads();
185   serial=0.0;
186   for (n=1; n <= number_threads; n++)
187   {
188     double
189       e,
190       parallel,
191       user_time;
192
193     TimerInfo
194       *timer;
195
196     SetOpenMPMaximumThreads(n);
197     timer=AcquireTimerInfo();
198     if (concurrent == MagickFalse)
199       {
200         for (i=0; i < (ssize_t) iterations; i++)
201         {
202           if (status != MagickFalse)
203             continue;
204           if (duration > 0)
205             {
206               if (GetElapsedTime(timer) > duration)
207                 continue;
208               (void) ContinueTimer(timer);
209             }
210           status=command(image_info,argc,argv,metadata,exception);
211           if (exception->severity != UndefinedException)
212             {
213               if ((exception->severity > ErrorException) ||
214                   (regard_warnings != MagickFalse))
215                 status=MagickTrue;
216               CatchException(exception);
217             }
218           if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
219             {
220               (void) fputs(*metadata,stdout);
221               (void) fputc('\n',stdout);
222               *metadata=DestroyString(*metadata);
223             }
224         }
225       }
226     else
227       {
228         SetOpenMPNested(1);
229 #if defined(MAGICKCORE_OPENMP_SUPPORT)
230         # pragma omp parallel for shared(status)
231 #endif
232         for (i=0; i < (ssize_t) iterations; i++)
233         {
234           if (status != MagickFalse)
235             continue;
236           if (duration > 0)
237             {
238               if (GetElapsedTime(timer) > duration)
239                 continue;
240               (void) ContinueTimer(timer);
241             }
242           status=command(image_info,argc,argv,metadata,exception);
243 #if defined(MAGICKCORE_OPENMP_SUPPORT)
244            # pragma omp critical (MagickCore_CommandGenesis)
245 #endif
246           {
247             if (exception->severity != UndefinedException)
248               {
249                 if ((exception->severity > ErrorException) ||
250                     (regard_warnings != MagickFalse))
251                   status=MagickTrue;
252                 CatchException(exception);
253               }
254             if ((metadata != (char **) NULL) && (*metadata != (char *) NULL))
255               {
256                 (void) fputs(*metadata,stdout);
257                 (void) fputc('\n',stdout);
258                 *metadata=DestroyString(*metadata);
259               }
260           }
261         }
262       }
263     user_time=GetUserTime(timer);
264     parallel=GetElapsedTime(timer);
265     e=1.0;
266     if (n == 1)
267       serial=parallel;
268     else
269       e=((1.0/(1.0/((serial/(serial+parallel))+(1.0-(serial/(serial+parallel)))/
270         (double) n)))-(1.0/(double) n))/(1.0-1.0/(double) n);
271     (void) FormatLocaleFile(stderr,
272       "Performance[%.20g]: %.20gi %0.3fips %0.3fe %0.3fu %lu:%02lu.%03lu\n",
273       (double) n,(double) iterations,(double) iterations/parallel,e,
274       user_time,(unsigned long) (parallel/60.0),(unsigned long)
275       floor(fmod(parallel,60.0)),(unsigned long)
276       (1000.0*(parallel-floor(parallel))+0.5));
277     timer=DestroyTimerInfo(timer);
278   }
279   return(status);
280 }
281 \f
282 /*
283 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
284 %                                                                             %
285 %                                                                             %
286 %                                                                             %
287 +     M o g r i f y I m a g e                                                 %
288 %                                                                             %
289 %                                                                             %
290 %                                                                             %
291 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
292 %
293 %  MogrifyImage() applies simple single image processing options to a single
294 %  image that may be part of a large list, but also handles any 'region'
295 %  image handling.
296 %
297 %  The image in the list may be modified in three different ways...
298 %
299 %    * directly modified (EG: -negate, -gamma, -level, -annotate, -draw),
300 %    * replaced by a new image (EG: -spread, -resize, -rotate, -morphology)
301 %    * replace by a list of images (only the -separate option!)
302 %
303 %  In each case the result is returned into the list, and a pointer to the
304 %  modified image (last image added if replaced by a list of images) is
305 %  returned.
306 %
307 %  ASIDE: The -crop is present but restricted to non-tile single image crops
308 %
309 %  This means if all the images are being processed (such as by
310 %  MogrifyImages(), next image to be processed will be as per the pointer
311 %  (*image)->next.  Also the image list may grow as a result of some specific
312 %  operations but as images are never merged or deleted, it will never shrink
313 %  in length.  Typically the list will remain the same length.
314 %
315 %  WARNING: As the image pointed to may be replaced, the first image in the
316 %  list may also change.  GetFirstImageInList() should be used by caller if
317 %  they wish return the Image pointer to the first image in list.
318 %
319 %
320 %  The format of the MogrifyImage method is:
321 %
322 %      MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
323 %        const char **argv,Image **image)
324 %
325 %  A description of each parameter follows:
326 %
327 %    o image_info: the image info..
328 %
329 %    o argc: Specifies a pointer to an integer describing the number of
330 %      elements in the argument vector.
331 %
332 %    o argv: Specifies a pointer to a text array containing the command line
333 %      arguments.
334 %
335 %    o image: the image.
336 %
337 %    o exception: return any errors or warnings in this structure.
338 %
339 */
340
341 static inline Image *GetImageCache(const ImageInfo *image_info,const char *path,
342   ExceptionInfo *exception)
343 {
344   char
345     key[MaxTextExtent];
346
347   ExceptionInfo
348     *sans_exception;
349
350   Image
351     *image;
352
353   ImageInfo
354     *read_info;
355
356   /*
357     Read an image into a image cache if not already present.  Return the image
358     that is in the cache under that filename.
359   */
360   (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",path);
361   sans_exception=AcquireExceptionInfo();
362   image=(Image *) GetImageRegistry(ImageRegistryType,key,sans_exception);
363   sans_exception=DestroyExceptionInfo(sans_exception);
364   if (image != (Image *) NULL)
365     return(image);
366   read_info=CloneImageInfo(image_info);
367   (void) CopyMagickString(read_info->filename,path,MaxTextExtent);
368   image=ReadImage(read_info,exception);
369   read_info=DestroyImageInfo(read_info);
370   if (image != (Image *) NULL)
371     (void) SetImageRegistry(ImageRegistryType,key,image,exception);
372   return(image);
373 }
374
375 static MagickBooleanType IsPathWritable(const char *path)
376 {
377   if (IsPathAccessible(path) == MagickFalse)
378     return(MagickFalse);
379   if (access_utf8(path,W_OK) != 0)
380     return(MagickFalse);
381   return(MagickTrue);
382 }
383
384 static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
385 {
386   if (x > y)
387     return(x);
388   return(y);
389 }
390
391 static MagickBooleanType MonitorProgress(const char *text,
392   const MagickOffsetType offset,const MagickSizeType extent,
393   void *wand_unused(client_data))
394 {
395   char
396     message[MaxTextExtent],
397     tag[MaxTextExtent];
398
399   const char
400     *locale_message;
401
402   register char
403     *p;
404
405   if (extent < 2)
406     return(MagickTrue);
407   (void) CopyMagickMemory(tag,text,MaxTextExtent);
408   p=strrchr(tag,'/');
409   if (p != (char *) NULL)
410     *p='\0';
411   (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
412   locale_message=GetLocaleMessage(message);
413   if (locale_message == message)
414     locale_message=tag;
415   if (p == (char *) NULL)
416     (void) FormatLocaleFile(stderr,"%s: %ld of %lu, %02ld%% complete\r",
417       locale_message,(long) offset,(unsigned long) extent,(long)
418       (100L*offset/(extent-1)));
419   else
420     (void) FormatLocaleFile(stderr,"%s[%s]: %ld of %lu, %02ld%% complete\r",
421       locale_message,p+1,(long) offset,(unsigned long) extent,(long)
422       (100L*offset/(extent-1)));
423   if (offset == (MagickOffsetType) (extent-1))
424     (void) FormatLocaleFile(stderr,"\n");
425   (void) fflush(stderr);
426   return(MagickTrue);
427 }
428
429 static Image *SparseColorOption(const Image *image,
430   const SparseColorMethod method,const char *arguments,
431   const MagickBooleanType color_from_image,ExceptionInfo *exception)
432 {
433   char
434     token[MaxTextExtent];
435
436   const char
437     *p;
438
439   double
440     *sparse_arguments;
441
442   Image
443     *sparse_image;
444
445   PixelInfo
446     color;
447
448   MagickBooleanType
449     error;
450
451   register size_t
452     x;
453
454   size_t
455     number_arguments,
456     number_colors;
457
458   /*
459     SparseColorOption() parses the complex -sparse-color argument into an an
460     array of floating point values then calls SparseColorImage().  Argument is
461     a complex mix of floating-point pixel coodinates, and color specifications
462     (or direct floating point numbers).  The number of floats needed to
463     represent a color varies depending on the current channel setting.
464   */
465   assert(image != (Image *) NULL);
466   assert(image->signature == MagickSignature);
467   if (image->debug != MagickFalse)
468     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
469   assert(exception != (ExceptionInfo *) NULL);
470   assert(exception->signature == MagickSignature);
471   /*
472     Limit channels according to image - and add up number of color channel.
473   */
474   number_colors=0;
475   if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
476     number_colors++;
477   if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
478     number_colors++;
479   if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
480     number_colors++;
481   if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
482       (image->colorspace == CMYKColorspace))
483     number_colors++;
484   if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
485       (image->matte != MagickFalse))
486     number_colors++;
487
488   /*
489     Read string, to determine number of arguments needed,
490   */
491   p=arguments;
492   x=0;
493   while( *p != '\0' )
494   {
495     GetMagickToken(p,&p,token);
496     if ( token[0] == ',' ) continue;
497     if ( isalpha((int) token[0]) || token[0] == '#' ) {
498       if ( color_from_image ) {
499         (void) ThrowMagickException(exception,GetMagickModule(),
500             OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
501             "Color arg given, when colors are coming from image");
502         return( (Image *)NULL);
503       }
504       x += number_colors;  /* color argument */
505     }
506     else {
507       x++;   /* floating point argument */
508     }
509   }
510   error=MagickTrue;
511   if ( color_from_image ) {
512     /* just the control points are being given */
513     error = ( x % 2 != 0 ) ? MagickTrue : MagickFalse;
514     number_arguments=(x/2)*(2+number_colors);
515   }
516   else {
517     /* control points and color values */
518     error = ( x % (2+number_colors) != 0 ) ? MagickTrue : MagickFalse;
519     number_arguments=x;
520   }
521   if ( error ) {
522     (void) ThrowMagickException(exception,GetMagickModule(),
523                OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
524                "Invalid number of Arguments");
525     return( (Image *)NULL);
526   }
527
528   /* Allocate and fill in the floating point arguments */
529   sparse_arguments=(double *) AcquireQuantumMemory(number_arguments,
530     sizeof(*sparse_arguments));
531   if (sparse_arguments == (double *) NULL) {
532     (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
533       "MemoryAllocationFailed","%s","SparseColorOption");
534     return( (Image *)NULL);
535   }
536   (void) ResetMagickMemory(sparse_arguments,0,number_arguments*
537     sizeof(*sparse_arguments));
538   p=arguments;
539   x=0;
540   while( *p != '\0' && x < number_arguments ) {
541     /* X coordinate */
542     token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
543     if ( token[0] == '\0' ) break;
544     if ( isalpha((int) token[0]) || token[0] == '#' ) {
545       (void) ThrowMagickException(exception,GetMagickModule(),
546             OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
547             "Color found, instead of X-coord");
548       error = MagickTrue;
549       break;
550     }
551     sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
552     /* Y coordinate */
553     token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
554     if ( token[0] == '\0' ) break;
555     if ( isalpha((int) token[0]) || token[0] == '#' ) {
556       (void) ThrowMagickException(exception,GetMagickModule(),
557             OptionError, "InvalidArgument", "`%s': %s", "sparse-color",
558             "Color found, instead of Y-coord");
559       error = MagickTrue;
560       break;
561     }
562     sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
563     /* color values for this control point */
564 #if 0
565     if ( (color_from_image ) {
566       /* get color from image */
567       /* HOW??? */
568     }
569     else
570 #endif
571     {
572       /* color name or function given in string argument */
573       token[0]=','; while ( token[0] == ',' ) GetMagickToken(p,&p,token);
574       if ( token[0] == '\0' ) break;
575       if ( isalpha((int) token[0]) || token[0] == '#' ) {
576         /* Color string given */
577         (void) QueryColorCompliance(token,AllCompliance,&color,exception);
578         if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
579           sparse_arguments[x++] = QuantumScale*color.red;
580         if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
581           sparse_arguments[x++] = QuantumScale*color.green;
582         if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
583           sparse_arguments[x++] = QuantumScale*color.blue;
584         if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
585             (image->colorspace == CMYKColorspace))
586           sparse_arguments[x++] = QuantumScale*color.black;
587         if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
588             (image->matte != MagickFalse))
589           sparse_arguments[x++] = QuantumScale*color.alpha;
590       }
591       else {
592         /* Colors given as a set of floating point values - experimental */
593         /* NB: token contains the first floating point value to use! */
594         if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
595           {
596           while ( token[0] == ',' ) GetMagickToken(p,&p,token);
597           if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
598             break;
599           sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
600           token[0] = ','; /* used this token - get another */
601         }
602         if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
603           {
604           while ( token[0] == ',' ) GetMagickToken(p,&p,token);
605           if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
606             break;
607           sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
608           token[0] = ','; /* used this token - get another */
609         }
610         if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
611           {
612           while ( token[0] == ',' ) GetMagickToken(p,&p,token);
613           if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
614             break;
615           sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
616           token[0] = ','; /* used this token - get another */
617         }
618         if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) &&
619             (image->colorspace == CMYKColorspace))
620           {
621           while ( token[0] == ',' ) GetMagickToken(p,&p,token);
622           if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
623             break;
624           sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
625           token[0] = ','; /* used this token - get another */
626         }
627         if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) &&
628             (image->matte != MagickFalse))
629           {
630           while ( token[0] == ',' ) GetMagickToken(p,&p,token);
631           if ( token[0] == '\0' || isalpha((int)token[0]) || token[0] == '#' )
632             break;
633           sparse_arguments[x++]=StringToDouble(token,(char **) NULL);
634           token[0] = ','; /* used this token - get another */
635         }
636       }
637     }
638   }
639   if ( number_arguments != x && !error ) {
640     (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
641       "InvalidArgument","`%s': %s","sparse-color","Argument Parsing Error");
642     sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
643     return( (Image *)NULL);
644   }
645   if ( error )
646     return( (Image *)NULL);
647
648   /* Call the Interpolation function with the parsed arguments */
649   sparse_image=SparseColorImage(image,method,number_arguments,sparse_arguments,
650     exception);
651   sparse_arguments=(double *) RelinquishMagickMemory(sparse_arguments);
652   return( sparse_image );
653 }
654
655 WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
656   const char **argv,Image **image,ExceptionInfo *exception)
657 {
658   ChannelType
659     channel;
660
661   CompositeOperator
662     compose;
663
664   const char
665     *format,
666     *option;
667
668   double
669     attenuate;
670
671   DrawInfo
672     *draw_info;
673
674   GeometryInfo
675     geometry_info;
676
677   Image
678     *region_image;
679
680   ImageInfo
681     *mogrify_info;
682
683   MagickStatusType
684     status;
685
686   PixelInfo
687     fill;
688
689   MagickStatusType
690     flags;
691
692   PixelInterpolateMethod
693     interpolate_method;
694
695   QuantizeInfo
696     *quantize_info;
697
698   RectangleInfo
699     geometry,
700     region_geometry;
701
702   register ssize_t
703     i;
704
705   /*
706     Initialize method variables.
707   */
708   assert(image_info != (const ImageInfo *) NULL);
709   assert(image_info->signature == MagickSignature);
710   assert(image != (Image **) NULL);
711   assert((*image)->signature == MagickSignature);
712   if ((*image)->debug != MagickFalse)
713     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
714   if (argc < 0)
715     return(MagickTrue);
716   mogrify_info=CloneImageInfo(image_info);
717   draw_info=CloneDrawInfo(mogrify_info,(DrawInfo *) NULL);
718   quantize_info=AcquireQuantizeInfo(mogrify_info);
719   SetGeometryInfo(&geometry_info);
720   GetPixelInfo(*image,&fill);
721   fill=(*image)->background_color;
722   attenuate=1.0;
723   compose=(*image)->compose;
724   interpolate_method=UndefinedInterpolatePixel;
725   channel=mogrify_info->channel;
726   format=GetImageOption(mogrify_info,"format");
727   SetGeometry(*image,&region_geometry);
728   region_image=NewImageList();
729   /*
730     Transmogrify the image.
731   */
732   for (i=0; i < (ssize_t) argc; i++)
733   {
734     Image
735       *mogrify_image;
736
737     ssize_t
738       count;
739
740     option=argv[i];
741     if (IsCommandOption(option) == MagickFalse)
742       continue;
743     count=MagickMax(ParseCommandOption(MagickCommandOptions,MagickFalse,option),
744       0L);
745     if ((i+count) >= (ssize_t) argc)
746       break;
747     status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
748     mogrify_image=(Image *)NULL;
749     switch (*(option+1))
750     {
751       case 'a':
752       {
753         if (LocaleCompare("adaptive-blur",option+1) == 0)
754           {
755             /*
756               Adaptive blur image.
757             */
758             (void) SyncImageSettings(mogrify_info,*image,exception);
759             flags=ParseGeometry(argv[i+1],&geometry_info);
760             if ((flags & SigmaValue) == 0)
761               geometry_info.sigma=1.0;
762             if ((flags & XiValue) == 0)
763               geometry_info.xi=0.0;
764             mogrify_image=AdaptiveBlurImage(*image,geometry_info.rho,
765               geometry_info.sigma,geometry_info.xi,exception);
766             break;
767           }
768         if (LocaleCompare("adaptive-resize",option+1) == 0)
769           {
770             /*
771               Adaptive resize image.
772             */
773             (void) SyncImageSettings(mogrify_info,*image,exception);
774             (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
775             mogrify_image=AdaptiveResizeImage(*image,geometry.width,
776               geometry.height,interpolate_method,exception);
777             break;
778           }
779         if (LocaleCompare("adaptive-sharpen",option+1) == 0)
780           {
781             /*
782               Adaptive sharpen image.
783             */
784             (void) SyncImageSettings(mogrify_info,*image,exception);
785             flags=ParseGeometry(argv[i+1],&geometry_info);
786             if ((flags & SigmaValue) == 0)
787               geometry_info.sigma=1.0;
788             if ((flags & XiValue) == 0)
789               geometry_info.xi=0.0;
790             mogrify_image=AdaptiveSharpenImage(*image,geometry_info.rho,
791               geometry_info.sigma,geometry_info.xi,exception);
792             break;
793           }
794         if (LocaleCompare("affine",option+1) == 0)
795           {
796             /*
797               Affine matrix.
798             */
799             if (*option == '+')
800               {
801                 GetAffineMatrix(&draw_info->affine);
802                 break;
803               }
804             (void) ParseAffineGeometry(argv[i+1],&draw_info->affine,exception);
805             break;
806           }
807         if (LocaleCompare("alpha",option+1) == 0)
808           {
809             AlphaChannelType
810               alpha_type;
811
812             (void) SyncImageSettings(mogrify_info,*image,exception);
813             alpha_type=(AlphaChannelType) ParseCommandOption(MagickAlphaOptions,
814               MagickFalse,argv[i+1]);
815             (void) SetImageAlphaChannel(*image,alpha_type,exception);
816             break;
817           }
818         if (LocaleCompare("annotate",option+1) == 0)
819           {
820             char
821               *text,
822               geometry[MaxTextExtent];
823
824             /*
825               Annotate image.
826             */
827             (void) SyncImageSettings(mogrify_info,*image,exception);
828             SetGeometryInfo(&geometry_info);
829             flags=ParseGeometry(argv[i+1],&geometry_info);
830             if ((flags & SigmaValue) == 0)
831               geometry_info.sigma=geometry_info.rho;
832             text=InterpretImageProperties(mogrify_info,*image,argv[i+2],
833               exception);
834             if (text == (char *) NULL)
835               break;
836             (void) CloneString(&draw_info->text,text);
837             text=DestroyString(text);
838             (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f",
839               geometry_info.xi,geometry_info.psi);
840             (void) CloneString(&draw_info->geometry,geometry);
841             draw_info->affine.sx=cos(DegreesToRadians(
842               fmod(geometry_info.rho,360.0)));
843             draw_info->affine.rx=sin(DegreesToRadians(
844               fmod(geometry_info.rho,360.0)));
845             draw_info->affine.ry=(-sin(DegreesToRadians(
846               fmod(geometry_info.sigma,360.0))));
847             draw_info->affine.sy=cos(DegreesToRadians(
848               fmod(geometry_info.sigma,360.0)));
849             (void) AnnotateImage(*image,draw_info,exception);
850             break;
851           }
852         if (LocaleCompare("antialias",option+1) == 0)
853           {
854             draw_info->stroke_antialias=(*option == '-') ? MagickTrue :
855               MagickFalse;
856             draw_info->text_antialias=(*option == '-') ? MagickTrue :
857               MagickFalse;
858             break;
859           }
860         if (LocaleCompare("attenuate",option+1) == 0)
861           {
862             if (*option == '+')
863               {
864                 attenuate=1.0;
865                 break;
866               }
867             attenuate=StringToDouble(argv[i+1],(char **) NULL);
868             break;
869           }
870         if (LocaleCompare("auto-gamma",option+1) == 0)
871           {
872             /*
873               Auto Adjust Gamma of image based on its mean
874             */
875             (void) SyncImageSettings(mogrify_info,*image,exception);
876             (void) AutoGammaImage(*image,exception);
877             break;
878           }
879         if (LocaleCompare("auto-level",option+1) == 0)
880           {
881             /*
882               Perfectly Normalize (max/min stretch) the image
883             */
884             (void) SyncImageSettings(mogrify_info,*image,exception);
885             (void) AutoLevelImage(*image,exception);
886             break;
887           }
888         if (LocaleCompare("auto-orient",option+1) == 0)
889           {
890             (void) SyncImageSettings(mogrify_info,*image,exception);
891             switch ((*image)->orientation)
892             {
893               case TopRightOrientation:
894               {
895                 mogrify_image=FlopImage(*image,exception);
896                 break;
897               }
898               case BottomRightOrientation:
899               {
900                 mogrify_image=RotateImage(*image,180.0,exception);
901                 break;
902               }
903               case BottomLeftOrientation:
904               {
905                 mogrify_image=FlipImage(*image,exception);
906                 break;
907               }
908               case LeftTopOrientation:
909               {
910                 mogrify_image=TransposeImage(*image,exception);
911                 break;
912               }
913               case RightTopOrientation:
914               {
915                 mogrify_image=RotateImage(*image,90.0,exception);
916                 break;
917               }
918               case RightBottomOrientation:
919               {
920                 mogrify_image=TransverseImage(*image,exception);
921                 break;
922               }
923               case LeftBottomOrientation:
924               {
925                 mogrify_image=RotateImage(*image,270.0,exception);
926                 break;
927               }
928               default:
929                 break;
930             }
931             if (mogrify_image != (Image *) NULL)
932               mogrify_image->orientation=TopLeftOrientation;
933             break;
934           }
935         break;
936       }
937       case 'b':
938       {
939         if (LocaleCompare("black-threshold",option+1) == 0)
940           {
941             /*
942               Black threshold image.
943             */
944             (void) SyncImageSettings(mogrify_info,*image,exception);
945             (void) BlackThresholdImage(*image,argv[i+1],exception);
946             break;
947           }
948         if (LocaleCompare("blue-shift",option+1) == 0)
949           {
950             /*
951               Blue shift image.
952             */
953             (void) SyncImageSettings(mogrify_info,*image,exception);
954             geometry_info.rho=1.5;
955             if (*option == '-')
956               flags=ParseGeometry(argv[i+1],&geometry_info);
957             mogrify_image=BlueShiftImage(*image,geometry_info.rho,exception);
958             break;
959           }
960         if (LocaleCompare("blur",option+1) == 0)
961           {
962             /*
963               Gaussian blur image.
964             */
965             (void) SyncImageSettings(mogrify_info,*image,exception);
966             flags=ParseGeometry(argv[i+1],&geometry_info);
967             if ((flags & SigmaValue) == 0)
968               geometry_info.sigma=1.0;
969             if ((flags & XiValue) == 0)
970               geometry_info.xi=0.0;
971             mogrify_image=BlurImage(*image,geometry_info.rho,
972               geometry_info.sigma,geometry_info.xi,exception);
973             break;
974           }
975         if (LocaleCompare("border",option+1) == 0)
976           {
977             /*
978               Surround image with a border of solid color.
979             */
980             (void) SyncImageSettings(mogrify_info,*image,exception);
981             flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
982             if ((flags & SigmaValue) == 0)
983               geometry.height=geometry.width;
984             mogrify_image=BorderImage(*image,&geometry,compose,exception);
985             break;
986           }
987         if (LocaleCompare("bordercolor",option+1) == 0)
988           {
989             if (*option == '+')
990               {
991                 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
992                   &draw_info->border_color,exception);
993                 break;
994               }
995             (void) QueryColorCompliance(argv[i+1],AllCompliance,
996               &draw_info->border_color,exception);
997             break;
998           }
999         if (LocaleCompare("box",option+1) == 0)
1000           {
1001             (void) QueryColorCompliance(argv[i+1],AllCompliance,
1002               &draw_info->undercolor,exception);
1003             break;
1004           }
1005         if (LocaleCompare("brightness-contrast",option+1) == 0)
1006           {
1007             double
1008               brightness,
1009               contrast;
1010
1011             GeometryInfo
1012               geometry_info;
1013
1014             MagickStatusType
1015               flags;
1016
1017             /*
1018               Brightness / contrast image.
1019             */
1020             (void) SyncImageSettings(mogrify_info,*image,exception);
1021             flags=ParseGeometry(argv[i+1],&geometry_info);
1022             brightness=geometry_info.rho;
1023             contrast=0.0;
1024             if ((flags & SigmaValue) != 0)
1025               contrast=geometry_info.sigma;
1026             (void) BrightnessContrastImage(*image,brightness,contrast,
1027               exception);
1028             break;
1029           }
1030         break;
1031       }
1032       case 'c':
1033       {
1034         if (LocaleCompare("cdl",option+1) == 0)
1035           {
1036             char
1037               *color_correction_collection;
1038
1039             /*
1040               Color correct with a color decision list.
1041             */
1042             (void) SyncImageSettings(mogrify_info,*image,exception);
1043             color_correction_collection=FileToString(argv[i+1],~0,exception);
1044             if (color_correction_collection == (char *) NULL)
1045               break;
1046             (void) ColorDecisionListImage(*image,color_correction_collection,
1047               exception);
1048             break;
1049           }
1050         if (LocaleCompare("channel",option+1) == 0)
1051           {
1052             if (*option == '+')
1053               channel=DefaultChannels;
1054             else
1055               channel=(ChannelType) ParseChannelOption(argv[i+1]);
1056             SetPixelChannelMapMask(*image,channel);
1057             break;
1058           }
1059         if (LocaleCompare("charcoal",option+1) == 0)
1060           {
1061             /*
1062               Charcoal image.
1063             */
1064             (void) SyncImageSettings(mogrify_info,*image,exception);
1065             flags=ParseGeometry(argv[i+1],&geometry_info);
1066             if ((flags & SigmaValue) == 0)
1067               geometry_info.sigma=1.0;
1068             if ((flags & XiValue) == 0)
1069               geometry_info.xi=1.0;
1070             mogrify_image=CharcoalImage(*image,geometry_info.rho,
1071               geometry_info.sigma,geometry_info.xi,exception);
1072             break;
1073           }
1074         if (LocaleCompare("chop",option+1) == 0)
1075           {
1076             /*
1077               Chop the image.
1078             */
1079             (void) SyncImageSettings(mogrify_info,*image,exception);
1080             (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1081             mogrify_image=ChopImage(*image,&geometry,exception);
1082             break;
1083           }
1084         if (LocaleCompare("clamp",option+1) == 0)
1085           {
1086             /*
1087               Clamp image.
1088             */
1089             (void) SyncImageSettings(mogrify_info,*image,exception);
1090             (void) ClampImage(*image,exception);
1091             break;
1092           }
1093         if (LocaleCompare("clip",option+1) == 0)
1094           {
1095             (void) SyncImageSettings(mogrify_info,*image,exception);
1096             if (*option == '+')
1097               {
1098                 (void) SetImageClipMask(*image,(Image *) NULL,exception);
1099                 break;
1100               }
1101             (void) ClipImage(*image,exception);
1102             break;
1103           }
1104         if (LocaleCompare("clip-mask",option+1) == 0)
1105           {
1106             CacheView
1107               *mask_view;
1108
1109             Image
1110               *mask_image;
1111
1112             register Quantum
1113               *restrict q;
1114
1115             register ssize_t
1116               x;
1117
1118             ssize_t
1119               y;
1120
1121             (void) SyncImageSettings(mogrify_info,*image,exception);
1122             if (*option == '+')
1123               {
1124                 /*
1125                   Remove a mask.
1126                 */
1127                 (void) SetImageMask(*image,(Image *) NULL,exception);
1128                 break;
1129               }
1130             /*
1131               Set the image mask.
1132               FUTURE: This Should Be a SetImageAlphaChannel() call, Or two.
1133             */
1134             mask_image=GetImageCache(mogrify_info,argv[i+1],exception);
1135             if (mask_image == (Image *) NULL)
1136               break;
1137             if (SetImageStorageClass(mask_image,DirectClass,exception) == MagickFalse)
1138               return(MagickFalse);
1139             mask_view=AcquireCacheView(mask_image);
1140             for (y=0; y < (ssize_t) mask_image->rows; y++)
1141             {
1142               q=GetCacheViewAuthenticPixels(mask_view,0,y,mask_image->columns,1,
1143                 exception);
1144               if (q == (Quantum *) NULL)
1145                 break;
1146               for (x=0; x < (ssize_t) mask_image->columns; x++)
1147               {
1148                 if (mask_image->matte == MagickFalse)
1149                   SetPixelAlpha(mask_image,GetPixelIntensity(mask_image,q),q);
1150                 SetPixelRed(mask_image,GetPixelAlpha(mask_image,q),q);
1151                 SetPixelGreen(mask_image,GetPixelAlpha(mask_image,q),q);
1152                 SetPixelBlue(mask_image,GetPixelAlpha(mask_image,q),q);
1153                 q+=GetPixelChannels(mask_image);
1154               }
1155               if (SyncCacheViewAuthenticPixels(mask_view,exception) == MagickFalse)
1156                 break;
1157             }
1158             mask_view=DestroyCacheView(mask_view);
1159             mask_image->matte=MagickTrue;
1160             (void) SetImageClipMask(*image,mask_image,exception);
1161             break;
1162           }
1163         if (LocaleCompare("clip-path",option+1) == 0)
1164           {
1165             (void) SyncImageSettings(mogrify_info,*image,exception);
1166             (void) ClipImagePath(*image,argv[i+1],*option == '-' ? MagickTrue :
1167               MagickFalse,exception);
1168             break;
1169           }
1170         if (LocaleCompare("colorize",option+1) == 0)
1171           {
1172             /*
1173               Colorize the image.
1174             */
1175             (void) SyncImageSettings(mogrify_info,*image,exception);
1176             mogrify_image=ColorizeImage(*image,argv[i+1],&fill,exception);
1177             break;
1178           }
1179         if (LocaleCompare("color-matrix",option+1) == 0)
1180           {
1181             KernelInfo
1182               *kernel;
1183
1184             (void) SyncImageSettings(mogrify_info,*image,exception);
1185             kernel=AcquireKernelInfo(argv[i+1]);
1186             if (kernel == (KernelInfo *) NULL)
1187               break;
1188             mogrify_image=ColorMatrixImage(*image,kernel,exception);
1189             kernel=DestroyKernelInfo(kernel);
1190             break;
1191           }
1192         if (LocaleCompare("colors",option+1) == 0)
1193           {
1194             /*
1195               Reduce the number of colors in the image.
1196             */
1197             (void) SyncImageSettings(mogrify_info,*image,exception);
1198             quantize_info->number_colors=StringToUnsignedLong(argv[i+1]);
1199             if (quantize_info->number_colors == 0)
1200               break;
1201             if (((*image)->storage_class == DirectClass) ||
1202                 (*image)->colors > quantize_info->number_colors)
1203               (void) QuantizeImage(quantize_info,*image,exception);
1204             else
1205               (void) CompressImageColormap(*image,exception);
1206             break;
1207           }
1208         if (LocaleCompare("colorspace",option+1) == 0)
1209           {
1210             ColorspaceType
1211               colorspace;
1212
1213             (void) SyncImageSettings(mogrify_info,*image,exception);
1214             if (*option == '+')
1215               {
1216                 (void) TransformImageColorspace(*image,RGBColorspace,exception);
1217                 break;
1218               }
1219             colorspace=(ColorspaceType) ParseCommandOption(
1220               MagickColorspaceOptions,MagickFalse,argv[i+1]);
1221             (void) TransformImageColorspace(*image,colorspace,exception);
1222             break;
1223           }
1224         if (LocaleCompare("compose",option+1) == 0)
1225           {
1226             (void) SyncImageSettings(mogrify_info,*image,exception);
1227             compose=(CompositeOperator) ParseCommandOption(MagickComposeOptions,
1228               MagickFalse,argv[i+1]);
1229             break;
1230           }
1231         if (LocaleCompare("contrast",option+1) == 0)
1232           {
1233             (void) SyncImageSettings(mogrify_info,*image,exception);
1234             (void) ContrastImage(*image,(*option == '-') ? MagickTrue :
1235               MagickFalse,exception);
1236             break;
1237           }
1238         if (LocaleCompare("contrast-stretch",option+1) == 0)
1239           {
1240             double
1241               black_point,
1242               white_point;
1243
1244             MagickStatusType
1245               flags;
1246
1247             /*
1248               Contrast stretch image.
1249             */
1250             (void) SyncImageSettings(mogrify_info,*image,exception);
1251             flags=ParseGeometry(argv[i+1],&geometry_info);
1252             black_point=geometry_info.rho;
1253             white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma :
1254               black_point;
1255             if ((flags & PercentValue) != 0)
1256               {
1257                 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
1258                 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
1259               }
1260             white_point=(MagickRealType) (*image)->columns*(*image)->rows-
1261               white_point;
1262             (void) ContrastStretchImage(*image,black_point,white_point,
1263               exception);
1264             break;
1265           }
1266         if (LocaleCompare("convolve",option+1) == 0)
1267           {
1268             KernelInfo
1269               *kernel_info;
1270
1271             (void) SyncImageSettings(mogrify_info,*image,exception);
1272             kernel_info=AcquireKernelInfo(argv[i+1]);
1273             if (kernel_info == (KernelInfo *) NULL)
1274               break;
1275             kernel_info->bias=(*image)->bias;
1276             mogrify_image=ConvolveImage(*image,kernel_info,exception);
1277             kernel_info=DestroyKernelInfo(kernel_info);
1278             break;
1279           }
1280         if (LocaleCompare("crop",option+1) == 0)
1281           {
1282             /*
1283               Crop a image to a smaller size
1284             */
1285             (void) SyncImageSettings(mogrify_info,*image,exception);
1286             mogrify_image=CropImageToTiles(*image,argv[i+1],exception);
1287             break;
1288           }
1289         if (LocaleCompare("cycle",option+1) == 0)
1290           {
1291             /*
1292               Cycle an image colormap.
1293             */
1294             (void) SyncImageSettings(mogrify_info,*image,exception);
1295             (void) CycleColormapImage(*image,(ssize_t) StringToLong(argv[i+1]),
1296               exception);
1297             break;
1298           }
1299         break;
1300       }
1301       case 'd':
1302       {
1303         if (LocaleCompare("decipher",option+1) == 0)
1304           {
1305             StringInfo
1306               *passkey;
1307
1308             /*
1309               Decipher pixels.
1310             */
1311             (void) SyncImageSettings(mogrify_info,*image,exception);
1312             passkey=FileToStringInfo(argv[i+1],~0,exception);
1313             if (passkey != (StringInfo *) NULL)
1314               {
1315                 (void) PasskeyDecipherImage(*image,passkey,exception);
1316                 passkey=DestroyStringInfo(passkey);
1317               }
1318             break;
1319           }
1320         if (LocaleCompare("density",option+1) == 0)
1321           {
1322             /*
1323               Set image density.
1324             */
1325             (void) CloneString(&draw_info->density,argv[i+1]);
1326             break;
1327           }
1328         if (LocaleCompare("depth",option+1) == 0)
1329           {
1330             (void) SyncImageSettings(mogrify_info,*image,exception);
1331             if (*option == '+')
1332               {
1333                 (void) SetImageDepth(*image,MAGICKCORE_QUANTUM_DEPTH,exception);
1334                 break;
1335               }
1336             (void) SetImageDepth(*image,StringToUnsignedLong(argv[i+1]),
1337               exception);
1338             break;
1339           }
1340         if (LocaleCompare("deskew",option+1) == 0)
1341           {
1342             double
1343               threshold;
1344
1345             /*
1346               Straighten the image.
1347             */
1348             (void) SyncImageSettings(mogrify_info,*image,exception);
1349             if (*option == '+')
1350               threshold=40.0*QuantumRange/100.0;
1351             else
1352               threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
1353                 1.0);
1354             mogrify_image=DeskewImage(*image,threshold,exception);
1355             break;
1356           }
1357         if (LocaleCompare("despeckle",option+1) == 0)
1358           {
1359             /*
1360               Reduce the speckles within an image.
1361             */
1362             (void) SyncImageSettings(mogrify_info,*image,exception);
1363             mogrify_image=DespeckleImage(*image,exception);
1364             break;
1365           }
1366         if (LocaleCompare("display",option+1) == 0)
1367           {
1368             (void) CloneString(&draw_info->server_name,argv[i+1]);
1369             break;
1370           }
1371         if (LocaleCompare("distort",option+1) == 0)
1372           {
1373             char
1374               *args,
1375               token[MaxTextExtent];
1376
1377             const char
1378               *p;
1379
1380             DistortImageMethod
1381               method;
1382
1383             double
1384               *arguments;
1385
1386             register ssize_t
1387               x;
1388
1389             size_t
1390               number_arguments;
1391
1392             /*
1393               Distort image.
1394             */
1395             (void) SyncImageSettings(mogrify_info,*image,exception);
1396             method=(DistortImageMethod) ParseCommandOption(MagickDistortOptions,
1397               MagickFalse,argv[i+1]);
1398             if (method == ResizeDistortion)
1399               {
1400                  double
1401                    resize_args[2];
1402
1403                  /*
1404                    Special Case - Argument is actually a resize geometry!
1405                    Convert that to an appropriate distortion argument array.
1406                  */
1407                  (void) ParseRegionGeometry(*image,argv[i+2],&geometry,
1408                    exception);
1409                  resize_args[0]=(double) geometry.width;
1410                  resize_args[1]=(double) geometry.height;
1411                  mogrify_image=DistortImage(*image,method,(size_t)2,
1412                    resize_args,MagickTrue,exception);
1413                  break;
1414               }
1415             args=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1416               exception);
1417             if (args == (char *) NULL)
1418               break;
1419             p=(char *) args;
1420             for (x=0; *p != '\0'; x++)
1421             {
1422               GetMagickToken(p,&p,token);
1423               if (*token == ',')
1424                 GetMagickToken(p,&p,token);
1425             }
1426             number_arguments=(size_t) x;
1427             arguments=(double *) AcquireQuantumMemory(number_arguments,
1428               sizeof(*arguments));
1429             if (arguments == (double *) NULL)
1430               ThrowWandFatalException(ResourceLimitFatalError,
1431                 "MemoryAllocationFailed",(*image)->filename);
1432             (void) ResetMagickMemory(arguments,0,number_arguments*
1433               sizeof(*arguments));
1434             p=(char *) args;
1435             for (x=0; (x < (ssize_t) number_arguments) && (*p != '\0'); x++)
1436             {
1437               GetMagickToken(p,&p,token);
1438               if (*token == ',')
1439                 GetMagickToken(p,&p,token);
1440               arguments[x]=StringToDouble(token,(char **) NULL);
1441             }
1442             args=DestroyString(args);
1443             mogrify_image=DistortImage(*image,method,number_arguments,arguments,
1444               (*option == '+') ? MagickTrue : MagickFalse,exception);
1445             arguments=(double *) RelinquishMagickMemory(arguments);
1446             break;
1447           }
1448         if (LocaleCompare("dither",option+1) == 0)
1449           {
1450             if (*option == '+')
1451               {
1452                 quantize_info->dither=MagickFalse;
1453                 break;
1454               }
1455             quantize_info->dither=MagickTrue;
1456             quantize_info->dither_method=(DitherMethod) ParseCommandOption(
1457               MagickDitherOptions,MagickFalse,argv[i+1]);
1458             if (quantize_info->dither_method == NoDitherMethod)
1459               quantize_info->dither=MagickFalse;
1460             break;
1461           }
1462         if (LocaleCompare("draw",option+1) == 0)
1463           {
1464             /*
1465               Draw image.
1466             */
1467             (void) SyncImageSettings(mogrify_info,*image,exception);
1468             (void) CloneString(&draw_info->primitive,argv[i+1]);
1469             (void) DrawImage(*image,draw_info,exception);
1470             break;
1471           }
1472         break;
1473       }
1474       case 'e':
1475       {
1476         if (LocaleCompare("edge",option+1) == 0)
1477           {
1478             /*
1479               Enhance edges in the image.
1480             */
1481             (void) SyncImageSettings(mogrify_info,*image,exception);
1482             flags=ParseGeometry(argv[i+1],&geometry_info);
1483             if ((flags & SigmaValue) == 0)
1484               geometry_info.sigma=1.0;
1485             mogrify_image=EdgeImage(*image,geometry_info.rho,
1486               geometry_info.sigma,exception);
1487             break;
1488           }
1489         if (LocaleCompare("emboss",option+1) == 0)
1490           {
1491             /*
1492               Gaussian embossen image.
1493             */
1494             (void) SyncImageSettings(mogrify_info,*image,exception);
1495             flags=ParseGeometry(argv[i+1],&geometry_info);
1496             if ((flags & SigmaValue) == 0)
1497               geometry_info.sigma=1.0;
1498             mogrify_image=EmbossImage(*image,geometry_info.rho,
1499               geometry_info.sigma,exception);
1500             break;
1501           }
1502         if (LocaleCompare("encipher",option+1) == 0)
1503           {
1504             StringInfo
1505               *passkey;
1506
1507             /*
1508               Encipher pixels.
1509             */
1510             (void) SyncImageSettings(mogrify_info,*image,exception);
1511             passkey=FileToStringInfo(argv[i+1],~0,exception);
1512             if (passkey != (StringInfo *) NULL)
1513               {
1514                 (void) PasskeyEncipherImage(*image,passkey,exception);
1515                 passkey=DestroyStringInfo(passkey);
1516               }
1517             break;
1518           }
1519         if (LocaleCompare("encoding",option+1) == 0)
1520           {
1521             (void) CloneString(&draw_info->encoding,argv[i+1]);
1522             break;
1523           }
1524         if (LocaleCompare("enhance",option+1) == 0)
1525           {
1526             /*
1527               Enhance image.
1528             */
1529             (void) SyncImageSettings(mogrify_info,*image,exception);
1530             mogrify_image=EnhanceImage(*image,exception);
1531             break;
1532           }
1533         if (LocaleCompare("equalize",option+1) == 0)
1534           {
1535             /*
1536               Equalize image.
1537             */
1538             (void) SyncImageSettings(mogrify_info,*image,exception);
1539             (void) EqualizeImage(*image,exception);
1540             break;
1541           }
1542         if (LocaleCompare("evaluate",option+1) == 0)
1543           {
1544             double
1545               constant;
1546
1547             MagickEvaluateOperator
1548               op;
1549
1550             (void) SyncImageSettings(mogrify_info,*image,exception);
1551             op=(MagickEvaluateOperator) ParseCommandOption(
1552               MagickEvaluateOptions,MagickFalse,argv[i+1]);
1553             constant=StringToDoubleInterval(argv[i+2],(double) QuantumRange+
1554               1.0);
1555             (void) EvaluateImage(*image,op,constant,exception);
1556             break;
1557           }
1558         if (LocaleCompare("extent",option+1) == 0)
1559           {
1560             /*
1561               Set the image extent.
1562             */
1563             (void) SyncImageSettings(mogrify_info,*image,exception);
1564             flags=ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
1565             if (geometry.width == 0)
1566               geometry.width=(*image)->columns;
1567             if (geometry.height == 0)
1568               geometry.height=(*image)->rows;
1569             mogrify_image=ExtentImage(*image,&geometry,exception);
1570             break;
1571           }
1572         break;
1573       }
1574       case 'f':
1575       {
1576         if (LocaleCompare("family",option+1) == 0)
1577           {
1578             if (*option == '+')
1579               {
1580                 if (draw_info->family != (char *) NULL)
1581                   draw_info->family=DestroyString(draw_info->family);
1582                 break;
1583               }
1584             (void) CloneString(&draw_info->family,argv[i+1]);
1585             break;
1586           }
1587         if (LocaleCompare("features",option+1) == 0)
1588           {
1589             if (*option == '+')
1590               {
1591                 (void) DeleteImageArtifact(*image,"identify:features");
1592                 break;
1593               }
1594             (void) SetImageArtifact(*image,"identify:features",argv[i+1]);
1595             break;
1596           }
1597         if (LocaleCompare("fill",option+1) == 0)
1598           {
1599             ExceptionInfo
1600               *sans;
1601
1602             GetPixelInfo(*image,&fill);
1603             if (*option == '+')
1604               {
1605                 (void) QueryColorCompliance("none",AllCompliance,&fill,
1606                   exception);
1607                 (void) QueryColorCompliance("none",AllCompliance,
1608                   &draw_info->fill,exception);
1609                 if (draw_info->fill_pattern != (Image *) NULL)
1610                   draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
1611                 break;
1612               }
1613             sans=AcquireExceptionInfo();
1614             (void) QueryColorCompliance(argv[i+1],AllCompliance,&fill,
1615               sans);
1616             status=QueryColorCompliance(argv[i+1],AllCompliance,
1617               &draw_info->fill,sans);
1618             sans=DestroyExceptionInfo(sans);
1619             if (status == MagickFalse)
1620               draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
1621                 exception);
1622             break;
1623           }
1624         if (LocaleCompare("flip",option+1) == 0)
1625           {
1626             /*
1627               Flip image scanlines.
1628             */
1629             (void) SyncImageSettings(mogrify_info,*image,exception);
1630             mogrify_image=FlipImage(*image,exception);
1631             break;
1632           }
1633         if (LocaleCompare("floodfill",option+1) == 0)
1634           {
1635             PixelInfo
1636               target;
1637
1638             /*
1639               Floodfill image.
1640             */
1641             (void) SyncImageSettings(mogrify_info,*image,exception);
1642             (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1643             (void) QueryColorCompliance(argv[i+2],AllCompliance,&target,
1644               exception);
1645             (void) FloodfillPaintImage(*image,draw_info,&target,geometry.x,
1646               geometry.y,*option == '-' ? MagickFalse : MagickTrue,exception);
1647             break;
1648           }
1649         if (LocaleCompare("flop",option+1) == 0)
1650           {
1651             /*
1652               Flop image scanlines.
1653             */
1654             (void) SyncImageSettings(mogrify_info,*image,exception);
1655             mogrify_image=FlopImage(*image,exception);
1656             break;
1657           }
1658         if (LocaleCompare("font",option+1) == 0)
1659           {
1660             if (*option == '+')
1661               {
1662                 if (draw_info->font != (char *) NULL)
1663                   draw_info->font=DestroyString(draw_info->font);
1664                 break;
1665               }
1666             (void) CloneString(&draw_info->font,argv[i+1]);
1667             break;
1668           }
1669         if (LocaleCompare("format",option+1) == 0)
1670           {
1671             format=argv[i+1];
1672             break;
1673           }
1674         if (LocaleCompare("frame",option+1) == 0)
1675           {
1676             FrameInfo
1677               frame_info;
1678
1679             /*
1680               Surround image with an ornamental border.
1681             */
1682             (void) SyncImageSettings(mogrify_info,*image,exception);
1683             flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
1684             frame_info.width=geometry.width;
1685             frame_info.height=geometry.height;
1686             if ((flags & HeightValue) == 0)
1687               frame_info.height=geometry.width;
1688             frame_info.outer_bevel=geometry.x;
1689             frame_info.inner_bevel=geometry.y;
1690             frame_info.x=(ssize_t) frame_info.width;
1691             frame_info.y=(ssize_t) frame_info.height;
1692             frame_info.width=(*image)->columns+2*frame_info.width;
1693             frame_info.height=(*image)->rows+2*frame_info.height;
1694             mogrify_image=FrameImage(*image,&frame_info,compose,exception);
1695             break;
1696           }
1697         if (LocaleCompare("function",option+1) == 0)
1698           {
1699             char
1700               *arguments,
1701               token[MaxTextExtent];
1702
1703             const char
1704               *p;
1705
1706             double
1707               *parameters;
1708
1709             MagickFunction
1710               function;
1711
1712             register ssize_t
1713               x;
1714
1715             size_t
1716               number_parameters;
1717
1718             /*
1719               Function Modify Image Values
1720             */
1721             (void) SyncImageSettings(mogrify_info,*image,exception);
1722             function=(MagickFunction) ParseCommandOption(MagickFunctionOptions,
1723               MagickFalse,argv[i+1]);
1724             arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
1725               exception);
1726             if (arguments == (char *) NULL)
1727               break;
1728             p=(char *) arguments;
1729             for (x=0; *p != '\0'; x++)
1730             {
1731               GetMagickToken(p,&p,token);
1732               if (*token == ',')
1733                 GetMagickToken(p,&p,token);
1734             }
1735             number_parameters=(size_t) x;
1736             parameters=(double *) AcquireQuantumMemory(number_parameters,
1737               sizeof(*parameters));
1738             if (parameters == (double *) NULL)
1739               ThrowWandFatalException(ResourceLimitFatalError,
1740                 "MemoryAllocationFailed",(*image)->filename);
1741             (void) ResetMagickMemory(parameters,0,number_parameters*
1742               sizeof(*parameters));
1743             p=(char *) arguments;
1744             for (x=0; (x < (ssize_t) number_parameters) && (*p != '\0'); x++)
1745             {
1746               GetMagickToken(p,&p,token);
1747               if (*token == ',')
1748                 GetMagickToken(p,&p,token);
1749               parameters[x]=StringToDouble(token,(char **) NULL);
1750             }
1751             arguments=DestroyString(arguments);
1752             (void) FunctionImage(*image,function,number_parameters,parameters,
1753               exception);
1754             parameters=(double *) RelinquishMagickMemory(parameters);
1755             break;
1756           }
1757         break;
1758       }
1759       case 'g':
1760       {
1761         if (LocaleCompare("gamma",option+1) == 0)
1762           {
1763             /*
1764               Gamma image.
1765             */
1766             (void) SyncImageSettings(mogrify_info,*image,exception);
1767             if (*option == '+')
1768               (*image)->gamma=StringToDouble(argv[i+1],(char **) NULL);
1769             else
1770               (void) GammaImage(*image,StringToDouble(argv[i+1],
1771                 (char **) NULL),exception);
1772             break;
1773           }
1774         if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
1775             (LocaleCompare("gaussian",option+1) == 0))
1776           {
1777             /*
1778               Gaussian blur image.
1779             */
1780             (void) SyncImageSettings(mogrify_info,*image,exception);
1781             flags=ParseGeometry(argv[i+1],&geometry_info);
1782             if ((flags & SigmaValue) == 0)
1783               geometry_info.sigma=1.0;
1784             if ((flags & XiValue) == 0)
1785               geometry_info.xi=0.0;
1786             mogrify_image=GaussianBlurImage(*image,geometry_info.rho,
1787               geometry_info.sigma,geometry_info.xi,exception);
1788             break;
1789           }
1790         if (LocaleCompare("geometry",option+1) == 0)
1791           {
1792               /*
1793                 Record Image offset, Resize last image.
1794               */
1795             (void) SyncImageSettings(mogrify_info,*image,exception);
1796             if (*option == '+')
1797               {
1798                 if ((*image)->geometry != (char *) NULL)
1799                   (*image)->geometry=DestroyString((*image)->geometry);
1800                 break;
1801               }
1802             flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
1803             if (((flags & XValue) != 0) || ((flags & YValue) != 0))
1804               (void) CloneString(&(*image)->geometry,argv[i+1]);
1805             else
1806               mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
1807                 (*image)->filter,(*image)->blur,exception);
1808             break;
1809           }
1810         if (LocaleCompare("gravity",option+1) == 0)
1811           {
1812             if (*option == '+')
1813               {
1814                 draw_info->gravity=UndefinedGravity;
1815                 break;
1816               }
1817             draw_info->gravity=(GravityType) ParseCommandOption(
1818               MagickGravityOptions,MagickFalse,argv[i+1]);
1819             break;
1820           }
1821         break;
1822       }
1823       case 'h':
1824       {
1825         if (LocaleCompare("highlight-color",option+1) == 0)
1826           {
1827             (void) SetImageArtifact(*image,option+1,argv[i+1]);
1828             break;
1829           }
1830         break;
1831       }
1832       case 'i':
1833       {
1834         if (LocaleCompare("identify",option+1) == 0)
1835           {
1836             char
1837               *text;
1838
1839             (void) SyncImageSettings(mogrify_info,*image,exception);
1840             if (format == (char *) NULL)
1841               {
1842                 (void) IdentifyImage(*image,stdout,mogrify_info->verbose,
1843                   exception);
1844                 break;
1845               }
1846             text=InterpretImageProperties(mogrify_info,*image,format,
1847               exception);
1848             if (text == (char *) NULL)
1849               break;
1850             (void) fputs(text,stdout);
1851             (void) fputc('\n',stdout);
1852             text=DestroyString(text);
1853             break;
1854           }
1855         if (LocaleCompare("implode",option+1) == 0)
1856           {
1857             /*
1858               Implode image.
1859             */
1860             (void) SyncImageSettings(mogrify_info,*image,exception);
1861             (void) ParseGeometry(argv[i+1],&geometry_info);
1862             mogrify_image=ImplodeImage(*image,geometry_info.rho,
1863               interpolate_method,exception);
1864             break;
1865           }
1866         if (LocaleCompare("interline-spacing",option+1) == 0)
1867           {
1868             if (*option == '+')
1869               (void) ParseGeometry("0",&geometry_info);
1870             else
1871               (void) ParseGeometry(argv[i+1],&geometry_info);
1872             draw_info->interline_spacing=geometry_info.rho;
1873             break;
1874           }
1875         if (LocaleCompare("interpolate",option+1) == 0)
1876           {
1877             interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
1878               MagickInterpolateOptions,MagickFalse,argv[i+1]);
1879             break;
1880           }
1881         if (LocaleCompare("interword-spacing",option+1) == 0)
1882           {
1883             if (*option == '+')
1884               (void) ParseGeometry("0",&geometry_info);
1885             else
1886               (void) ParseGeometry(argv[i+1],&geometry_info);
1887             draw_info->interword_spacing=geometry_info.rho;
1888             break;
1889           }
1890         break;
1891       }
1892       case 'k':
1893       {
1894         if (LocaleCompare("kerning",option+1) == 0)
1895           {
1896             if (*option == '+')
1897               (void) ParseGeometry("0",&geometry_info);
1898             else
1899               (void) ParseGeometry(argv[i+1],&geometry_info);
1900             draw_info->kerning=geometry_info.rho;
1901             break;
1902           }
1903         break;
1904       }
1905       case 'l':
1906       {
1907         if (LocaleCompare("lat",option+1) == 0)
1908           {
1909             /*
1910               Local adaptive threshold image.
1911             */
1912             (void) SyncImageSettings(mogrify_info,*image,exception);
1913             flags=ParseGeometry(argv[i+1],&geometry_info);
1914             if ((flags & PercentValue) != 0)
1915               geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
1916             mogrify_image=AdaptiveThresholdImage(*image,(size_t)
1917               geometry_info.rho,(size_t) geometry_info.sigma,(double)
1918               geometry_info.xi,exception);
1919             break;
1920           }
1921         if (LocaleCompare("level",option+1) == 0)
1922           {
1923             MagickRealType
1924               black_point,
1925               gamma,
1926               white_point;
1927
1928             MagickStatusType
1929               flags;
1930
1931             /*
1932               Parse levels.
1933             */
1934             (void) SyncImageSettings(mogrify_info,*image,exception);
1935             flags=ParseGeometry(argv[i+1],&geometry_info);
1936             black_point=geometry_info.rho;
1937             white_point=(MagickRealType) QuantumRange;
1938             if ((flags & SigmaValue) != 0)
1939               white_point=geometry_info.sigma;
1940             gamma=1.0;
1941             if ((flags & XiValue) != 0)
1942               gamma=geometry_info.xi;
1943             if ((flags & PercentValue) != 0)
1944               {
1945                 black_point*=(MagickRealType) (QuantumRange/100.0);
1946                 white_point*=(MagickRealType) (QuantumRange/100.0);
1947               }
1948             if ((flags & SigmaValue) == 0)
1949               white_point=(MagickRealType) QuantumRange-black_point;
1950             if ((*option == '+') || ((flags & AspectValue) != 0))
1951               (void) LevelizeImage(*image,black_point,white_point,gamma,
1952                 exception);
1953             else
1954               (void) LevelImage(*image,black_point,white_point,gamma,
1955                 exception);
1956             break;
1957           }
1958         if (LocaleCompare("level-colors",option+1) == 0)
1959           {
1960             char
1961               token[MaxTextExtent];
1962
1963             const char
1964               *p;
1965
1966             PixelInfo
1967               black_point,
1968               white_point;
1969
1970             p=(const char *) argv[i+1];
1971             GetMagickToken(p,&p,token);  /* get black point color */
1972             if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1973               (void) QueryColorCompliance(token,AllCompliance,
1974                 &black_point,exception);
1975             else
1976               (void) QueryColorCompliance("#000000",AllCompliance,
1977                 &black_point,exception);
1978             if (isalpha((int) token[0]) || (token[0] == '#'))
1979               GetMagickToken(p,&p,token);
1980             if (*token == '\0')
1981               white_point=black_point; /* set everything to that color */
1982             else
1983               {
1984                 if ((isalpha((int) *token) == 0) && ((*token == '#') == 0))
1985                   GetMagickToken(p,&p,token); /* Get white point color. */
1986                 if ((isalpha((int) *token) != 0) || ((*token == '#') != 0))
1987                   (void) QueryColorCompliance(token,AllCompliance,
1988                     &white_point,exception);
1989                 else
1990                   (void) QueryColorCompliance("#ffffff",AllCompliance,
1991                     &white_point,exception);
1992               }
1993             (void) LevelImageColors(*image,&black_point,&white_point,
1994               *option == '+' ? MagickTrue : MagickFalse,exception);
1995             break;
1996           }
1997         if (LocaleCompare("linear-stretch",option+1) == 0)
1998           {
1999             double
2000               black_point,
2001               white_point;
2002
2003             MagickStatusType
2004               flags;
2005
2006             (void) SyncImageSettings(mogrify_info,*image,exception);
2007             flags=ParseGeometry(argv[i+1],&geometry_info);
2008             black_point=geometry_info.rho;
2009             white_point=(MagickRealType) (*image)->columns*(*image)->rows;
2010             if ((flags & SigmaValue) != 0)
2011               white_point=geometry_info.sigma;
2012             if ((flags & PercentValue) != 0)
2013               {
2014                 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
2015                 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
2016               }
2017             if ((flags & SigmaValue) == 0)
2018               white_point=(MagickRealType) (*image)->columns*(*image)->rows-
2019                 black_point;
2020             (void) LinearStretchImage(*image,black_point,white_point,exception);
2021             break;
2022           }
2023         if (LocaleCompare("linewidth",option+1) == 0)
2024           {
2025             draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
2026             break;
2027           }
2028         if (LocaleCompare("liquid-rescale",option+1) == 0)
2029           {
2030             /*
2031               Liquid rescale image.
2032             */
2033             (void) SyncImageSettings(mogrify_info,*image,exception);
2034             flags=ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2035             if ((flags & XValue) == 0)
2036               geometry.x=1;
2037             if ((flags & YValue) == 0)
2038               geometry.y=0;
2039             mogrify_image=LiquidRescaleImage(*image,geometry.width,
2040               geometry.height,1.0*geometry.x,1.0*geometry.y,exception);
2041             break;
2042           }
2043         if (LocaleCompare("lowlight-color",option+1) == 0)
2044           {
2045             (void) SetImageArtifact(*image,option+1,argv[i+1]);
2046             break;
2047           }
2048         break;
2049       }
2050       case 'm':
2051       {
2052         if (LocaleCompare("map",option+1) == 0)
2053           {
2054             Image
2055               *remap_image;
2056
2057             /*
2058               Transform image colors to match this set of colors.
2059             */
2060             (void) SyncImageSettings(mogrify_info,*image,exception);
2061             if (*option == '+')
2062               break;
2063             remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2064             if (remap_image == (Image *) NULL)
2065               break;
2066             (void) RemapImage(quantize_info,*image,remap_image,exception);
2067             remap_image=DestroyImage(remap_image);
2068             break;
2069           }
2070         if (LocaleCompare("mask",option+1) == 0)
2071           {
2072             Image
2073               *mask;
2074
2075             (void) SyncImageSettings(mogrify_info,*image,exception);
2076             if (*option == '+')
2077               {
2078                 /*
2079                   Remove a mask.
2080                 */
2081                 (void) SetImageMask(*image,(Image *) NULL,exception);
2082                 break;
2083               }
2084             /*
2085               Set the image mask.
2086             */
2087             mask=GetImageCache(mogrify_info,argv[i+1],exception);
2088             if (mask == (Image *) NULL)
2089               break;
2090             (void) SetImageMask(*image,mask,exception);
2091             mask=DestroyImage(mask);
2092             break;
2093           }
2094         if (LocaleCompare("matte",option+1) == 0)
2095           {
2096             (void) SetImageAlphaChannel(*image,(*option == '-') ?
2097               SetAlphaChannel : DeactivateAlphaChannel,exception);
2098             break;
2099           }
2100         if (LocaleCompare("median",option+1) == 0)
2101           {
2102             /*
2103               Median filter image.
2104             */
2105             (void) SyncImageSettings(mogrify_info,*image,exception);
2106             flags=ParseGeometry(argv[i+1],&geometry_info);
2107             if ((flags & SigmaValue) == 0)
2108               geometry_info.sigma=geometry_info.rho;
2109             mogrify_image=StatisticImage(*image,MedianStatistic,(size_t)
2110               geometry_info.rho,(size_t) geometry_info.sigma,exception);
2111             break;
2112           }
2113         if (LocaleCompare("mode",option+1) == 0)
2114           {
2115             /*
2116               Mode image.
2117             */
2118             (void) SyncImageSettings(mogrify_info,*image,exception);
2119             flags=ParseGeometry(argv[i+1],&geometry_info);
2120             if ((flags & SigmaValue) == 0)
2121               geometry_info.sigma=geometry_info.rho;
2122             mogrify_image=StatisticImage(*image,ModeStatistic,(size_t)
2123               geometry_info.rho,(size_t) geometry_info.sigma,exception);
2124             break;
2125           }
2126         if (LocaleCompare("modulate",option+1) == 0)
2127           {
2128             (void) SyncImageSettings(mogrify_info,*image,exception);
2129             (void) ModulateImage(*image,argv[i+1],exception);
2130             break;
2131           }
2132         if (LocaleCompare("monitor",option+1) == 0)
2133           {
2134             if (*option == '+')
2135               {
2136                 (void) SetImageProgressMonitor(*image,
2137                   (MagickProgressMonitor) NULL,(void *) NULL);
2138                 break;
2139               }
2140             (void) SetImageProgressMonitor(*image,MonitorProgress,
2141               (void *) NULL);
2142             break;
2143           }
2144         if (LocaleCompare("monochrome",option+1) == 0)
2145           {
2146             (void) SyncImageSettings(mogrify_info,*image,exception);
2147             (void) SetImageType(*image,BilevelType,exception);
2148             break;
2149           }
2150         if (LocaleCompare("morphology",option+1) == 0)
2151           {
2152             char
2153               token[MaxTextExtent];
2154
2155             const char
2156               *p;
2157
2158             KernelInfo
2159               *kernel;
2160
2161             MorphologyMethod
2162               method;
2163
2164             ssize_t
2165               iterations;
2166
2167             /*
2168               Morphological Image Operation
2169             */
2170             (void) SyncImageSettings(mogrify_info,*image,exception);
2171             p=argv[i+1];
2172             GetMagickToken(p,&p,token);
2173             method=(MorphologyMethod) ParseCommandOption(
2174               MagickMorphologyOptions,MagickFalse,token);
2175             iterations=1L;
2176             GetMagickToken(p,&p,token);
2177             if ((*p == ':') || (*p == ','))
2178               GetMagickToken(p,&p,token);
2179             if ((*p != '\0'))
2180               iterations=(ssize_t) StringToLong(p);
2181             kernel=AcquireKernelInfo(argv[i+2]);
2182             if (kernel == (KernelInfo *) NULL)
2183               {
2184                 (void) ThrowMagickException(exception,GetMagickModule(),
2185                   OptionError,"UnabletoParseKernel","morphology");
2186                 status=MagickFalse;
2187                 break;
2188               }
2189             mogrify_image=MorphologyImage(*image,method,iterations,kernel,
2190               exception);
2191             kernel=DestroyKernelInfo(kernel);
2192             break;
2193           }
2194         if (LocaleCompare("motion-blur",option+1) == 0)
2195           {
2196             /*
2197               Motion blur image.
2198             */
2199             (void) SyncImageSettings(mogrify_info,*image,exception);
2200             flags=ParseGeometry(argv[i+1],&geometry_info);
2201             if ((flags & SigmaValue) == 0)
2202               geometry_info.sigma=1.0;
2203             mogrify_image=MotionBlurImage(*image,geometry_info.rho,
2204               geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
2205             break;
2206           }
2207         break;
2208       }
2209       case 'n':
2210       {
2211         if (LocaleCompare("negate",option+1) == 0)
2212           {
2213             (void) SyncImageSettings(mogrify_info,*image,exception);
2214             (void) NegateImage(*image,*option == '+' ? MagickTrue :
2215               MagickFalse,exception);
2216             break;
2217           }
2218         if (LocaleCompare("noise",option+1) == 0)
2219           {
2220             (void) SyncImageSettings(mogrify_info,*image,exception);
2221             if (*option == '-')
2222               {
2223                 flags=ParseGeometry(argv[i+1],&geometry_info);
2224                 if ((flags & SigmaValue) == 0)
2225                   geometry_info.sigma=geometry_info.rho;
2226                 mogrify_image=StatisticImage(*image,NonpeakStatistic,(size_t)
2227                   geometry_info.rho,(size_t) geometry_info.sigma,exception);
2228               }
2229             else
2230               {
2231                 NoiseType
2232                   noise;
2233
2234                 noise=(NoiseType) ParseCommandOption(MagickNoiseOptions,
2235                   MagickFalse,argv[i+1]);
2236                 mogrify_image=AddNoiseImage(*image,noise,attenuate,exception);
2237               }
2238             break;
2239           }
2240         if (LocaleCompare("normalize",option+1) == 0)
2241           {
2242             (void) SyncImageSettings(mogrify_info,*image,exception);
2243             (void) NormalizeImage(*image,exception);
2244             break;
2245           }
2246         break;
2247       }
2248       case 'o':
2249       {
2250         if (LocaleCompare("opaque",option+1) == 0)
2251           {
2252             PixelInfo
2253               target;
2254
2255             (void) SyncImageSettings(mogrify_info,*image,exception);
2256             (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
2257               exception);
2258             (void) OpaquePaintImage(*image,&target,&fill,*option == '-' ?
2259               MagickFalse : MagickTrue,exception);
2260             break;
2261           }
2262         if (LocaleCompare("ordered-dither",option+1) == 0)
2263           {
2264             (void) SyncImageSettings(mogrify_info,*image,exception);
2265             (void) OrderedPosterizeImage(*image,argv[i+1],exception);
2266             break;
2267           }
2268         break;
2269       }
2270       case 'p':
2271       {
2272         if (LocaleCompare("paint",option+1) == 0)
2273           {
2274             (void) SyncImageSettings(mogrify_info,*image,exception);
2275             (void) ParseGeometry(argv[i+1],&geometry_info);
2276             mogrify_image=OilPaintImage(*image,geometry_info.rho,
2277               geometry_info.sigma,exception);
2278             break;
2279           }
2280         if (LocaleCompare("pen",option+1) == 0)
2281           {
2282             if (*option == '+')
2283               {
2284                 (void) QueryColorCompliance("none",AllCompliance,
2285                   &draw_info->fill,exception);
2286                 break;
2287               }
2288             (void) QueryColorCompliance(argv[i+1],AllCompliance,
2289               &draw_info->fill,exception);
2290             break;
2291           }
2292         if (LocaleCompare("pointsize",option+1) == 0)
2293           {
2294             if (*option == '+')
2295               (void) ParseGeometry("12",&geometry_info);
2296             else
2297               (void) ParseGeometry(argv[i+1],&geometry_info);
2298             draw_info->pointsize=geometry_info.rho;
2299             break;
2300           }
2301         if (LocaleCompare("polaroid",option+1) == 0)
2302           {
2303             const char
2304               *caption;
2305
2306             double
2307               angle;
2308
2309             RandomInfo
2310               *random_info;
2311
2312             /*
2313               Simulate a Polaroid picture.
2314             */
2315             (void) SyncImageSettings(mogrify_info,*image,exception);
2316             random_info=AcquireRandomInfo();
2317             angle=22.5*(GetPseudoRandomValue(random_info)-0.5);
2318             random_info=DestroyRandomInfo(random_info);
2319             if (*option == '-')
2320               {
2321                 SetGeometryInfo(&geometry_info);
2322                 flags=ParseGeometry(argv[i+1],&geometry_info);
2323                 angle=geometry_info.rho;
2324               }
2325             caption=GetImageProperty(*image,"caption",exception);
2326             mogrify_image=PolaroidImage(*image,draw_info,caption,angle,
2327               interpolate_method,exception);
2328             break;
2329           }
2330         if (LocaleCompare("posterize",option+1) == 0)
2331           {
2332             /*
2333               Posterize image.
2334             */
2335             (void) SyncImageSettings(mogrify_info,*image,exception);
2336             (void) PosterizeImage(*image,StringToUnsignedLong(argv[i+1]),
2337               quantize_info->dither,exception);
2338             break;
2339           }
2340         if (LocaleCompare("preview",option+1) == 0)
2341           {
2342             PreviewType
2343               preview_type;
2344
2345             /*
2346               Preview image.
2347             */
2348             (void) SyncImageSettings(mogrify_info,*image,exception);
2349             if (*option == '+')
2350               preview_type=UndefinedPreview;
2351             else
2352               preview_type=(PreviewType) ParseCommandOption(
2353                 MagickPreviewOptions,MagickFalse,argv[i+1]);
2354             mogrify_image=PreviewImage(*image,preview_type,exception);
2355             break;
2356           }
2357         if (LocaleCompare("profile",option+1) == 0)
2358           {
2359             const char
2360               *name;
2361
2362             const StringInfo
2363               *profile;
2364
2365             Image
2366               *profile_image;
2367
2368             ImageInfo
2369               *profile_info;
2370
2371             (void) SyncImageSettings(mogrify_info,*image,exception);
2372             if (*option == '+')
2373               {
2374                 /*
2375                   Remove a profile from the image.
2376                 */
2377                 (void) ProfileImage(*image,argv[i+1],(const unsigned char *)
2378                   NULL,0,exception);
2379                 break;
2380               }
2381             /*
2382               Associate a profile with the image.
2383             */
2384             profile_info=CloneImageInfo(mogrify_info);
2385             profile=GetImageProfile(*image,"iptc");
2386             if (profile != (StringInfo *) NULL)
2387               profile_info->profile=(void *) CloneStringInfo(profile);
2388             profile_image=GetImageCache(profile_info,argv[i+1],exception);
2389             profile_info=DestroyImageInfo(profile_info);
2390             if (profile_image == (Image *) NULL)
2391               {
2392                 StringInfo
2393                   *profile;
2394
2395                 profile_info=CloneImageInfo(mogrify_info);
2396                 (void) CopyMagickString(profile_info->filename,argv[i+1],
2397                   MaxTextExtent);
2398                 profile=FileToStringInfo(profile_info->filename,~0UL,exception);
2399                 if (profile != (StringInfo *) NULL)
2400                   {
2401                     (void) ProfileImage(*image,profile_info->magick,
2402                       GetStringInfoDatum(profile),(size_t)
2403                       GetStringInfoLength(profile),exception);
2404                     profile=DestroyStringInfo(profile);
2405                   }
2406                 profile_info=DestroyImageInfo(profile_info);
2407                 break;
2408               }
2409             ResetImageProfileIterator(profile_image);
2410             name=GetNextImageProfile(profile_image);
2411             while (name != (const char *) NULL)
2412             {
2413               profile=GetImageProfile(profile_image,name);
2414               if (profile != (StringInfo *) NULL)
2415                 (void) ProfileImage(*image,name,GetStringInfoDatum(profile),
2416                   (size_t) GetStringInfoLength(profile),exception);
2417               name=GetNextImageProfile(profile_image);
2418             }
2419             profile_image=DestroyImage(profile_image);
2420             break;
2421           }
2422         break;
2423       }
2424       case 'q':
2425       {
2426         if (LocaleCompare("quantize",option+1) == 0)
2427           {
2428             if (*option == '+')
2429               {
2430                 quantize_info->colorspace=UndefinedColorspace;
2431                 break;
2432               }
2433             quantize_info->colorspace=(ColorspaceType) ParseCommandOption(
2434               MagickColorspaceOptions,MagickFalse,argv[i+1]);
2435             break;
2436           }
2437         break;
2438       }
2439       case 'r':
2440       {
2441         if (LocaleCompare("radial-blur",option+1) == 0)
2442           {
2443             /*
2444               Radial blur image.
2445             */
2446             (void) SyncImageSettings(mogrify_info,*image,exception);
2447             flags=ParseGeometry(argv[i+1],&geometry_info);
2448             mogrify_image=RadialBlurImage(*image,geometry_info.rho,
2449               geometry_info.sigma,exception);
2450             break;
2451           }
2452         if (LocaleCompare("raise",option+1) == 0)
2453           {
2454             /*
2455               Surround image with a raise of solid color.
2456             */
2457             flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2458             if ((flags & SigmaValue) == 0)
2459               geometry.height=geometry.width;
2460             (void) RaiseImage(*image,&geometry,*option == '-' ? MagickTrue :
2461               MagickFalse,exception);
2462             break;
2463           }
2464         if (LocaleCompare("random-threshold",option+1) == 0)
2465           {
2466             /*
2467               Threshold image.
2468             */
2469             (void) SyncImageSettings(mogrify_info,*image,exception);
2470             (void) RandomThresholdImage(*image,argv[i+1],exception);
2471             break;
2472           }
2473         if (LocaleCompare("recolor",option+1) == 0)
2474           {
2475             KernelInfo
2476               *kernel;
2477
2478             (void) SyncImageSettings(mogrify_info,*image,exception);
2479             kernel=AcquireKernelInfo(argv[i+1]);
2480             if (kernel == (KernelInfo *) NULL)
2481               break;
2482             mogrify_image=ColorMatrixImage(*image,kernel,exception);
2483             kernel=DestroyKernelInfo(kernel);
2484             break;
2485           }
2486         if (LocaleCompare("region",option+1) == 0)
2487           {
2488             (void) SyncImageSettings(mogrify_info,*image,exception);
2489             if (region_image != (Image *) NULL)
2490               {
2491                 /*
2492                   Composite region.
2493                 */
2494                 (void) CompositeImage(region_image,region_image->matte !=
2495                    MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
2496                    region_geometry.x,region_geometry.y,exception);
2497                 *image=DestroyImage(*image);
2498                 *image=region_image;
2499                 region_image = (Image *) NULL;
2500               }
2501             if (*option == '+')
2502               break;
2503             /*
2504               Apply transformations to a selected region of the image.
2505             */
2506             (void) ParseGravityGeometry(*image,argv[i+1],&region_geometry,
2507               exception);
2508             mogrify_image=CropImage(*image,&region_geometry,exception);
2509             if (mogrify_image == (Image *) NULL)
2510               break;
2511             region_image=(*image);
2512             *image=mogrify_image;
2513             mogrify_image=(Image *) NULL;
2514             break;
2515           }
2516         if (LocaleCompare("render",option+1) == 0)
2517           {
2518             (void) SyncImageSettings(mogrify_info,*image,exception);
2519             draw_info->render=(*option == '+') ? MagickTrue : MagickFalse;
2520             break;
2521           }
2522         if (LocaleCompare("remap",option+1) == 0)
2523           {
2524             Image
2525               *remap_image;
2526
2527             /*
2528               Transform image colors to match this set of colors.
2529             */
2530             (void) SyncImageSettings(mogrify_info,*image,exception);
2531             if (*option == '+')
2532               break;
2533             remap_image=GetImageCache(mogrify_info,argv[i+1],exception);
2534             if (remap_image == (Image *) NULL)
2535               break;
2536             (void) RemapImage(quantize_info,*image,remap_image,exception);
2537             remap_image=DestroyImage(remap_image);
2538             break;
2539           }
2540         if (LocaleCompare("repage",option+1) == 0)
2541           {
2542             if (*option == '+')
2543               {
2544                 (void) ParseAbsoluteGeometry("0x0+0+0",&(*image)->page);
2545                 break;
2546               }
2547             (void) ResetImagePage(*image,argv[i+1]);
2548             break;
2549           }
2550         if (LocaleCompare("resample",option+1) == 0)
2551           {
2552             /*
2553               Resample image.
2554             */
2555             (void) SyncImageSettings(mogrify_info,*image,exception);
2556             flags=ParseGeometry(argv[i+1],&geometry_info);
2557             if ((flags & SigmaValue) == 0)
2558               geometry_info.sigma=geometry_info.rho;
2559             mogrify_image=ResampleImage(*image,geometry_info.rho,
2560               geometry_info.sigma,(*image)->filter,(*image)->blur,exception);
2561             break;
2562           }
2563         if (LocaleCompare("resize",option+1) == 0)
2564           {
2565             /*
2566               Resize image.
2567             */
2568             (void) SyncImageSettings(mogrify_info,*image,exception);
2569             (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2570             mogrify_image=ResizeImage(*image,geometry.width,geometry.height,
2571               (*image)->filter,(*image)->blur,exception);
2572             break;
2573           }
2574         if (LocaleCompare("roll",option+1) == 0)
2575           {
2576             /*
2577               Roll image.
2578             */
2579             (void) SyncImageSettings(mogrify_info,*image,exception);
2580             (void) ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2581             mogrify_image=RollImage(*image,geometry.x,geometry.y,exception);
2582             break;
2583           }
2584         if (LocaleCompare("rotate",option+1) == 0)
2585           {
2586             char
2587               *geometry;
2588
2589             /*
2590               Check for conditional image rotation.
2591             */
2592             (void) SyncImageSettings(mogrify_info,*image,exception);
2593             if (strchr(argv[i+1],'>') != (char *) NULL)
2594               if ((*image)->columns <= (*image)->rows)
2595                 break;
2596             if (strchr(argv[i+1],'<') != (char *) NULL)
2597               if ((*image)->columns >= (*image)->rows)
2598                 break;
2599             /*
2600               Rotate image.
2601             */
2602             geometry=ConstantString(argv[i+1]);
2603             (void) SubstituteString(&geometry,">","");
2604             (void) SubstituteString(&geometry,"<","");
2605             (void) ParseGeometry(geometry,&geometry_info);
2606             geometry=DestroyString(geometry);
2607             mogrify_image=RotateImage(*image,geometry_info.rho,exception);
2608             break;
2609           }
2610         break;
2611       }
2612       case 's':
2613       {
2614         if (LocaleCompare("sample",option+1) == 0)
2615           {
2616             /*
2617               Sample image with pixel replication.
2618             */
2619             (void) SyncImageSettings(mogrify_info,*image,exception);
2620             (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2621             mogrify_image=SampleImage(*image,geometry.width,geometry.height,
2622               exception);
2623             break;
2624           }
2625         if (LocaleCompare("scale",option+1) == 0)
2626           {
2627             /*
2628               Resize image.
2629             */
2630             (void) SyncImageSettings(mogrify_info,*image,exception);
2631             (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2632             mogrify_image=ScaleImage(*image,geometry.width,geometry.height,
2633               exception);
2634             break;
2635           }
2636         if (LocaleCompare("selective-blur",option+1) == 0)
2637           {
2638             /*
2639               Selectively blur pixels within a contrast threshold.
2640             */
2641             (void) SyncImageSettings(mogrify_info,*image,exception);
2642             flags=ParseGeometry(argv[i+1],&geometry_info);
2643             if ((flags & PercentValue) != 0)
2644               geometry_info.xi=(double) QuantumRange*geometry_info.xi/100.0;
2645             mogrify_image=SelectiveBlurImage(*image,geometry_info.rho,
2646               geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
2647             break;
2648           }
2649         if (LocaleCompare("separate",option+1) == 0)
2650           {
2651             /*
2652               Break channels into separate images.
2653             */
2654             (void) SyncImageSettings(mogrify_info,*image,exception);
2655             mogrify_image=SeparateImages(*image,exception);
2656             break;
2657           }
2658         if (LocaleCompare("sepia-tone",option+1) == 0)
2659           {
2660             double
2661               threshold;
2662
2663             /*
2664               Sepia-tone image.
2665             */
2666             (void) SyncImageSettings(mogrify_info,*image,exception);
2667             threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2668               1.0);
2669             mogrify_image=SepiaToneImage(*image,threshold,exception);
2670             break;
2671           }
2672         if (LocaleCompare("segment",option+1) == 0)
2673           {
2674             /*
2675               Segment image.
2676             */
2677             (void) SyncImageSettings(mogrify_info,*image,exception);
2678             flags=ParseGeometry(argv[i+1],&geometry_info);
2679             if ((flags & SigmaValue) == 0)
2680               geometry_info.sigma=1.0;
2681             (void) SegmentImage(*image,(*image)->colorspace,
2682               mogrify_info->verbose,geometry_info.rho,geometry_info.sigma,
2683               exception);
2684             break;
2685           }
2686         if (LocaleCompare("set",option+1) == 0)
2687           {
2688             char
2689               *value;
2690
2691             /*
2692               Set image option.
2693             */
2694             if (*option == '+')
2695               {
2696                 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2697                   (void) DeleteImageRegistry(argv[i+1]+9);
2698                 else
2699                   if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2700                     {
2701                       (void) DeleteImageOption(mogrify_info,argv[i+1]+7);
2702                       (void) DeleteImageArtifact(*image,argv[i+1]+7);
2703                     }
2704                   else
2705                     (void) DeleteImageProperty(*image,argv[i+1]);
2706                 break;
2707               }
2708             value=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2709               exception);
2710             if (value == (char *) NULL)
2711               break;
2712             if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
2713               (void) SetImageRegistry(StringRegistryType,argv[i+1]+9,value,
2714                 exception);
2715             else
2716               if (LocaleNCompare(argv[i+1],"option:",7) == 0)
2717                 {
2718                   (void) SetImageOption(image_info,argv[i+1]+7,value);
2719                   (void) SetImageOption(mogrify_info,argv[i+1]+7,value);
2720                   (void) SetImageArtifact(*image,argv[i+1]+7,value);
2721                 }
2722               else
2723                 (void) SetImageProperty(*image,argv[i+1],value,exception);
2724             value=DestroyString(value);
2725             break;
2726           }
2727         if (LocaleCompare("shade",option+1) == 0)
2728           {
2729             /*
2730               Shade image.
2731             */
2732             (void) SyncImageSettings(mogrify_info,*image,exception);
2733             flags=ParseGeometry(argv[i+1],&geometry_info);
2734             if ((flags & SigmaValue) == 0)
2735               geometry_info.sigma=1.0;
2736             mogrify_image=ShadeImage(*image,(*option == '-') ? MagickTrue :
2737               MagickFalse,geometry_info.rho,geometry_info.sigma,exception);
2738             break;
2739           }
2740         if (LocaleCompare("shadow",option+1) == 0)
2741           {
2742             /*
2743               Shadow image.
2744             */
2745             (void) SyncImageSettings(mogrify_info,*image,exception);
2746             flags=ParseGeometry(argv[i+1],&geometry_info);
2747             if ((flags & SigmaValue) == 0)
2748               geometry_info.sigma=1.0;
2749             if ((flags & XiValue) == 0)
2750               geometry_info.xi=4.0;
2751             if ((flags & PsiValue) == 0)
2752               geometry_info.psi=4.0;
2753             mogrify_image=ShadowImage(*image,geometry_info.rho,
2754               geometry_info.sigma,(*image)->bias,(ssize_t)
2755               ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),
2756               exception);
2757             break;
2758           }
2759         if (LocaleCompare("sharpen",option+1) == 0)
2760           {
2761             /*
2762               Sharpen image.
2763             */
2764             (void) SyncImageSettings(mogrify_info,*image,exception);
2765             flags=ParseGeometry(argv[i+1],&geometry_info);
2766             if ((flags & SigmaValue) == 0)
2767               geometry_info.sigma=1.0;
2768             if ((flags & XiValue) == 0)
2769               geometry_info.xi=0.0;
2770             mogrify_image=SharpenImage(*image,geometry_info.rho,
2771               geometry_info.sigma,geometry_info.xi,exception);
2772             break;
2773           }
2774         if (LocaleCompare("shave",option+1) == 0)
2775           {
2776             /*
2777               Shave the image edges.
2778             */
2779             (void) SyncImageSettings(mogrify_info,*image,exception);
2780             flags=ParsePageGeometry(*image,argv[i+1],&geometry,exception);
2781             mogrify_image=ShaveImage(*image,&geometry,exception);
2782             break;
2783           }
2784         if (LocaleCompare("shear",option+1) == 0)
2785           {
2786             /*
2787               Shear image.
2788             */
2789             (void) SyncImageSettings(mogrify_info,*image,exception);
2790             flags=ParseGeometry(argv[i+1],&geometry_info);
2791             if ((flags & SigmaValue) == 0)
2792               geometry_info.sigma=geometry_info.rho;
2793             mogrify_image=ShearImage(*image,geometry_info.rho,
2794               geometry_info.sigma,exception);
2795             break;
2796           }
2797         if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
2798           {
2799             /*
2800               Sigmoidal non-linearity contrast control.
2801             */
2802             (void) SyncImageSettings(mogrify_info,*image,exception);
2803             flags=ParseGeometry(argv[i+1],&geometry_info);
2804             if ((flags & SigmaValue) == 0)
2805               geometry_info.sigma=(double) QuantumRange/2.0;
2806             if ((flags & PercentValue) != 0)
2807               geometry_info.sigma=(double) QuantumRange*geometry_info.sigma/
2808                 100.0;
2809             (void) SigmoidalContrastImage(*image,(*option == '-') ?
2810               MagickTrue : MagickFalse,geometry_info.rho,geometry_info.sigma,
2811               exception);
2812             break;
2813           }
2814         if (LocaleCompare("sketch",option+1) == 0)
2815           {
2816             /*
2817               Sketch image.
2818             */
2819             (void) SyncImageSettings(mogrify_info,*image,exception);
2820             flags=ParseGeometry(argv[i+1],&geometry_info);
2821             if ((flags & SigmaValue) == 0)
2822               geometry_info.sigma=1.0;
2823             mogrify_image=SketchImage(*image,geometry_info.rho,
2824               geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
2825             break;
2826           }
2827         if (LocaleCompare("solarize",option+1) == 0)
2828           {
2829             double
2830               threshold;
2831
2832             (void) SyncImageSettings(mogrify_info,*image,exception);
2833             threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2834               1.0);
2835             (void) SolarizeImage(*image,threshold,exception);
2836             break;
2837           }
2838         if (LocaleCompare("sparse-color",option+1) == 0)
2839           {
2840             SparseColorMethod
2841               method;
2842
2843             char
2844               *arguments;
2845
2846             /*
2847               Sparse Color Interpolated Gradient
2848             */
2849             (void) SyncImageSettings(mogrify_info,*image,exception);
2850             method=(SparseColorMethod) ParseCommandOption(
2851               MagickSparseColorOptions,MagickFalse,argv[i+1]);
2852             arguments=InterpretImageProperties(mogrify_info,*image,argv[i+2],
2853               exception);
2854             if (arguments == (char *) NULL)
2855               break;
2856             mogrify_image=SparseColorOption(*image,method,arguments,
2857               option[0] == '+' ? MagickTrue : MagickFalse,exception);
2858             arguments=DestroyString(arguments);
2859             break;
2860           }
2861         if (LocaleCompare("splice",option+1) == 0)
2862           {
2863             /*
2864               Splice a solid color into the image.
2865             */
2866             (void) SyncImageSettings(mogrify_info,*image,exception);
2867             (void) ParseGravityGeometry(*image,argv[i+1],&geometry,exception);
2868             mogrify_image=SpliceImage(*image,&geometry,exception);
2869             break;
2870           }
2871         if (LocaleCompare("spread",option+1) == 0)
2872           {
2873             /*
2874               Spread an image.
2875             */
2876             (void) SyncImageSettings(mogrify_info,*image,exception);
2877             (void) ParseGeometry(argv[i+1],&geometry_info);
2878             mogrify_image=SpreadImage(*image,geometry_info.rho,
2879               interpolate_method,exception);
2880             break;
2881           }
2882         if (LocaleCompare("statistic",option+1) == 0)
2883           {
2884             StatisticType
2885               type;
2886
2887             (void) SyncImageSettings(mogrify_info,*image,exception);
2888             type=(StatisticType) ParseCommandOption(MagickStatisticOptions,
2889               MagickFalse,argv[i+1]);
2890             (void) ParseGeometry(argv[i+2],&geometry_info);
2891             mogrify_image=StatisticImage(*image,type,(size_t) geometry_info.rho,
2892               (size_t) geometry_info.sigma,exception);
2893             break;
2894           }
2895         if (LocaleCompare("stretch",option+1) == 0)
2896           {
2897             if (*option == '+')
2898               {
2899                 draw_info->stretch=UndefinedStretch;
2900                 break;
2901               }
2902             draw_info->stretch=(StretchType) ParseCommandOption(
2903               MagickStretchOptions,MagickFalse,argv[i+1]);
2904             break;
2905           }
2906         if (LocaleCompare("strip",option+1) == 0)
2907           {
2908             /*
2909               Strip image of profiles and comments.
2910             */
2911             (void) SyncImageSettings(mogrify_info,*image,exception);
2912             (void) StripImage(*image,exception);
2913             break;
2914           }
2915         if (LocaleCompare("stroke",option+1) == 0)
2916           {
2917             ExceptionInfo
2918               *sans;
2919
2920             if (*option == '+')
2921               {
2922                 (void) QueryColorCompliance("none",AllCompliance,
2923                   &draw_info->stroke,exception);
2924                 if (draw_info->stroke_pattern != (Image *) NULL)
2925                   draw_info->stroke_pattern=DestroyImage(
2926                     draw_info->stroke_pattern);
2927                 break;
2928               }
2929             sans=AcquireExceptionInfo();
2930             status=QueryColorCompliance(argv[i+1],AllCompliance,
2931               &draw_info->stroke,sans);
2932             sans=DestroyExceptionInfo(sans);
2933             if (status == MagickFalse)
2934               draw_info->stroke_pattern=GetImageCache(mogrify_info,argv[i+1],
2935                 exception);
2936             break;
2937           }
2938         if (LocaleCompare("strokewidth",option+1) == 0)
2939           {
2940             draw_info->stroke_width=StringToDouble(argv[i+1],(char **) NULL);
2941             break;
2942           }
2943         if (LocaleCompare("style",option+1) == 0)
2944           {
2945             if (*option == '+')
2946               {
2947                 draw_info->style=UndefinedStyle;
2948                 break;
2949               }
2950             draw_info->style=(StyleType) ParseCommandOption(MagickStyleOptions,
2951               MagickFalse,argv[i+1]);
2952             break;
2953           }
2954         if (LocaleCompare("swirl",option+1) == 0)
2955           {
2956             /*
2957               Swirl image.
2958             */
2959             (void) SyncImageSettings(mogrify_info,*image,exception);
2960             (void) ParseGeometry(argv[i+1],&geometry_info);
2961             mogrify_image=SwirlImage(*image,geometry_info.rho,
2962               interpolate_method,exception);
2963             break;
2964           }
2965         break;
2966       }
2967       case 't':
2968       {
2969         if (LocaleCompare("threshold",option+1) == 0)
2970           {
2971             double
2972               threshold;
2973
2974             /*
2975               Threshold image.
2976             */
2977             (void) SyncImageSettings(mogrify_info,*image,exception);
2978             if (*option == '+')
2979               threshold=(double) QuantumRange/2;
2980             else
2981               threshold=StringToDoubleInterval(argv[i+1],(double) QuantumRange+
2982                 1.0);
2983             (void) BilevelImage(*image,threshold,exception);
2984             break;
2985           }
2986         if (LocaleCompare("thumbnail",option+1) == 0)
2987           {
2988             /*
2989               Thumbnail image.
2990             */
2991             (void) SyncImageSettings(mogrify_info,*image,exception);
2992             (void) ParseRegionGeometry(*image,argv[i+1],&geometry,exception);
2993             mogrify_image=ThumbnailImage(*image,geometry.width,geometry.height,
2994               exception);
2995             break;
2996           }
2997         if (LocaleCompare("tile",option+1) == 0)
2998           {
2999             if (*option == '+')
3000               {
3001                 if (draw_info->fill_pattern != (Image *) NULL)
3002                   draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern);
3003                 break;
3004               }
3005             draw_info->fill_pattern=GetImageCache(mogrify_info,argv[i+1],
3006               exception);
3007             break;
3008           }
3009         if (LocaleCompare("tint",option+1) == 0)
3010           {
3011             /*
3012               Tint the image.
3013             */
3014             (void) SyncImageSettings(mogrify_info,*image,exception);
3015             mogrify_image=TintImage(*image,argv[i+1],&fill,exception);
3016             break;
3017           }
3018         if (LocaleCompare("transform",option+1) == 0)
3019           {
3020             /*
3021               Affine transform image.
3022             */
3023             (void) SyncImageSettings(mogrify_info,*image,exception);
3024             mogrify_image=AffineTransformImage(*image,&draw_info->affine,
3025               exception);
3026             break;
3027           }
3028         if (LocaleCompare("transparent",option+1) == 0)
3029           {
3030             PixelInfo
3031               target;
3032
3033             (void) SyncImageSettings(mogrify_info,*image,exception);
3034             (void) QueryColorCompliance(argv[i+1],AllCompliance,&target,
3035               exception);
3036             (void) TransparentPaintImage(*image,&target,(Quantum)
3037               TransparentAlpha,*option == '-' ? MagickFalse : MagickTrue,
3038               exception);
3039             break;
3040           }
3041         if (LocaleCompare("transpose",option+1) == 0)
3042           {
3043             /*
3044               Transpose image scanlines.
3045             */
3046             (void) SyncImageSettings(mogrify_info,*image,exception);
3047             mogrify_image=TransposeImage(*image,exception);
3048             break;
3049           }
3050         if (LocaleCompare("transverse",option+1) == 0)
3051           {
3052             /*
3053               Transverse image scanlines.
3054             */
3055             (void) SyncImageSettings(mogrify_info,*image,exception);
3056             mogrify_image=TransverseImage(*image,exception);
3057             break;
3058           }
3059         if (LocaleCompare("treedepth",option+1) == 0)
3060           {
3061             quantize_info->tree_depth=StringToUnsignedLong(argv[i+1]);
3062             break;
3063           }
3064         if (LocaleCompare("trim",option+1) == 0)
3065           {
3066             /*
3067               Trim image.
3068             */
3069             (void) SyncImageSettings(mogrify_info,*image,exception);
3070             mogrify_image=TrimImage(*image,exception);
3071             break;
3072           }
3073         if (LocaleCompare("type",option+1) == 0)
3074           {
3075             ImageType
3076               type;
3077
3078             (void) SyncImageSettings(mogrify_info,*image,exception);
3079             if (*option == '+')
3080               type=UndefinedType;
3081             else
3082               type=(ImageType) ParseCommandOption(MagickTypeOptions,MagickFalse,
3083                 argv[i+1]);
3084             (*image)->type=UndefinedType;
3085             (void) SetImageType(*image,type,exception);
3086             break;
3087           }
3088         break;
3089       }
3090       case 'u':
3091       {
3092         if (LocaleCompare("undercolor",option+1) == 0)
3093           {
3094             (void) QueryColorCompliance(argv[i+1],AllCompliance,
3095               &draw_info->undercolor,exception);
3096             break;
3097           }
3098         if (LocaleCompare("unique",option+1) == 0)
3099           {
3100             if (*option == '+')
3101               {
3102                 (void) DeleteImageArtifact(*image,"identify:unique-colors");
3103                 break;
3104               }
3105             (void) SetImageArtifact(*image,"identify:unique-colors","true");
3106             (void) SetImageArtifact(*image,"verbose","true");
3107             break;
3108           }
3109         if (LocaleCompare("unique-colors",option+1) == 0)
3110           {
3111             /*
3112               Unique image colors.
3113             */
3114             (void) SyncImageSettings(mogrify_info,*image,exception);
3115             mogrify_image=UniqueImageColors(*image,exception);
3116             break;
3117           }
3118         if (LocaleCompare("unsharp",option+1) == 0)
3119           {
3120             /*
3121               Unsharp mask image.
3122             */
3123             (void) SyncImageSettings(mogrify_info,*image,exception);
3124             flags=ParseGeometry(argv[i+1],&geometry_info);
3125             if ((flags & SigmaValue) == 0)
3126               geometry_info.sigma=1.0;
3127             if ((flags & XiValue) == 0)
3128               geometry_info.xi=1.0;
3129             if ((flags & PsiValue) == 0)
3130               geometry_info.psi=0.05;
3131             mogrify_image=UnsharpMaskImage(*image,geometry_info.rho,
3132               geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception);
3133             break;
3134           }
3135         break;
3136       }
3137       case 'v':
3138       {
3139         if (LocaleCompare("verbose",option+1) == 0)
3140           {
3141             (void) SetImageArtifact(*image,option+1,
3142               *option == '+' ? "false" : "true");
3143             break;
3144           }
3145         if (LocaleCompare("vignette",option+1) == 0)
3146           {
3147             /*
3148               Vignette image.
3149             */
3150             (void) SyncImageSettings(mogrify_info,*image,exception);
3151             flags=ParseGeometry(argv[i+1],&geometry_info);
3152             if ((flags & SigmaValue) == 0)
3153               geometry_info.sigma=1.0;
3154             if ((flags & XiValue) == 0)
3155               geometry_info.xi=0.1*(*image)->columns;
3156             if ((flags & PsiValue) == 0)
3157               geometry_info.psi=0.1*(*image)->rows;
3158             mogrify_image=VignetteImage(*image,geometry_info.rho,
3159               geometry_info.sigma,(*image)->bias,(ssize_t)
3160               ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-0.5),
3161               exception);
3162             break;
3163           }
3164         if (LocaleCompare("virtual-pixel",option+1) == 0)
3165           {
3166             if (*option == '+')
3167               {
3168                 (void) SetImageVirtualPixelMethod(*image,
3169                   UndefinedVirtualPixelMethod);
3170                 break;
3171               }
3172             (void) SetImageVirtualPixelMethod(*image,(VirtualPixelMethod)
3173               ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
3174               argv[i+1]));
3175             break;
3176           }
3177         break;
3178       }
3179       case 'w':
3180       {
3181         if (LocaleCompare("wave",option+1) == 0)
3182           {
3183             /*
3184               Wave image.
3185             */
3186             (void) SyncImageSettings(mogrify_info,*image,exception);
3187             flags=ParseGeometry(argv[i+1],&geometry_info);
3188             if ((flags & SigmaValue) == 0)
3189               geometry_info.sigma=1.0;
3190             mogrify_image=WaveImage(*image,geometry_info.rho,
3191               geometry_info.sigma,interpolate_method,exception);
3192             break;
3193           }
3194         if (LocaleCompare("weight",option+1) == 0)
3195           {
3196             draw_info->weight=StringToUnsignedLong(argv[i+1]);
3197             if (LocaleCompare(argv[i+1],"all") == 0)
3198               draw_info->weight=0;
3199             if (LocaleCompare(argv[i+1],"bold") == 0)
3200               draw_info->weight=700;
3201             if (LocaleCompare(argv[i+1],"bolder") == 0)
3202               if (draw_info->weight <= 800)
3203                 draw_info->weight+=100;
3204             if (LocaleCompare(argv[i+1],"lighter") == 0)
3205               if (draw_info->weight >= 100)
3206                 draw_info->weight-=100;
3207             if (LocaleCompare(argv[i+1],"normal") == 0)
3208               draw_info->weight=400;
3209             break;
3210           }
3211         if (LocaleCompare("white-threshold",option+1) == 0)
3212           {
3213             /*
3214               White threshold image.
3215             */
3216             (void) SyncImageSettings(mogrify_info,*image,exception);
3217             (void) WhiteThresholdImage(*image,argv[i+1],exception);
3218             break;
3219           }
3220         break;
3221       }
3222       default:
3223         break;
3224     }
3225     /*
3226        Replace current image with any image that was generated
3227     */
3228     if (mogrify_image != (Image *) NULL)
3229       ReplaceImageInListReturnLast(image,mogrify_image);
3230     i+=count;
3231   }
3232   if (region_image != (Image *) NULL)
3233     {
3234       /*
3235         Composite transformed region onto image.
3236       */
3237       (void) SyncImageSettings(mogrify_info,*image,exception);
3238       (void) CompositeImage(region_image,region_image->matte !=
3239          MagickFalse ? CopyCompositeOp : OverCompositeOp,*image,
3240          region_geometry.x,region_geometry.y,exception);
3241       *image=DestroyImage(*image);
3242       *image=region_image;
3243       region_image = (Image *) NULL;
3244     }
3245   /*
3246     Free resources.
3247   */
3248   quantize_info=DestroyQuantizeInfo(quantize_info);
3249   draw_info=DestroyDrawInfo(draw_info);
3250   mogrify_info=DestroyImageInfo(mogrify_info);
3251   status=(MagickStatusType) (exception->severity == UndefinedException ? 1 : 0);
3252   return(status == 0 ? MagickFalse : MagickTrue);
3253 }
3254 \f
3255 /*
3256 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3257 %                                                                             %
3258 %                                                                             %
3259 %                                                                             %
3260 +    M o g r i f y I m a g e C o m m a n d                                    %
3261 %                                                                             %
3262 %                                                                             %
3263 %                                                                             %
3264 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3265 %
3266 %  MogrifyImageCommand() transforms an image or a sequence of images. These
3267 %  transforms include image scaling, image rotation, color reduction, and
3268 %  others. The transmogrified image overwrites the original image.
3269 %
3270 %  The format of the MogrifyImageCommand method is:
3271 %
3272 %      MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,int argc,
3273 %        const char **argv,char **metadata,ExceptionInfo *exception)
3274 %
3275 %  A description of each parameter follows:
3276 %
3277 %    o image_info: the image info.
3278 %
3279 %    o argc: the number of elements in the argument vector.
3280 %
3281 %    o argv: A text array containing the command line arguments.
3282 %
3283 %    o metadata: any metadata is returned here.
3284 %
3285 %    o exception: return any errors or warnings in this structure.
3286 %
3287 */
3288
3289 static MagickBooleanType MogrifyUsage(void)
3290 {
3291   static const char
3292     *miscellaneous[]=
3293     {
3294       "-debug events        display copious debugging information",
3295       "-help                print program options",
3296       "-list type           print a list of supported option arguments",
3297       "-log format          format of debugging information",
3298       "-version             print version information",
3299       (char *) NULL
3300     },
3301     *operators[]=
3302     {
3303       "-adaptive-blur geometry",
3304       "                     adaptively blur pixels; decrease effect near edges",
3305       "-adaptive-resize geometry",
3306       "                     adaptively resize image using 'mesh' interpolation",
3307       "-adaptive-sharpen geometry",
3308       "                     adaptively sharpen pixels; increase effect near edges",
3309       "-alpha option        on, activate, off, deactivate, set, opaque, copy",
3310       "                     transparent, extract, background, or shape",
3311       "-annotate geometry text",
3312       "                     annotate the image with text",
3313       "-auto-gamma          automagically adjust gamma level of image",
3314       "-auto-level          automagically adjust color levels of image",
3315       "-auto-orient         automagically orient (rotate) image",
3316       "-bench iterations    measure performance",
3317       "-black-threshold value",
3318       "                     force all pixels below the threshold into black",
3319       "-blue-shift          simulate a scene at nighttime in the moonlight",
3320       "-blur geometry       reduce image noise and reduce detail levels",
3321       "-border geometry     surround image with a border of color",
3322       "-bordercolor color   border color",
3323       "-brightness-contrast geometry",
3324       "                     improve brightness / contrast of the image",
3325       "-cdl filename        color correct with a color decision list",
3326       "-charcoal geometry   simulate a charcoal drawing",
3327       "-chop geometry       remove pixels from the image interior",
3328       "-clamp               restrict pixel range from 0 to the quantum depth",
3329       "-clip                clip along the first path from the 8BIM profile",
3330       "-clip-mask filename  associate a clip mask with the image",
3331       "-clip-path id        clip along a named path from the 8BIM profile",
3332       "-colorize value      colorize the image with the fill color",
3333       "-color-matrix matrix apply color correction to the image",
3334       "-contrast            enhance or reduce the image contrast",
3335       "-contrast-stretch geometry",
3336       "                     improve contrast by `stretching' the intensity range",
3337       "-convolve coefficients",
3338       "                     apply a convolution kernel to the image",
3339       "-cycle amount        cycle the image colormap",
3340       "-decipher filename   convert cipher pixels to plain pixels",
3341       "-deskew threshold    straighten an image",
3342       "-despeckle           reduce the speckles within an image",
3343       "-distort method args",
3344       "                     distort images according to given method ad args",
3345       "-draw string         annotate the image with a graphic primitive",
3346       "-edge radius         apply a filter to detect edges in the image",
3347       "-encipher filename   convert plain pixels to cipher pixels",
3348       "-emboss radius       emboss an image",
3349       "-enhance             apply a digital filter to enhance a noisy image",
3350       "-equalize            perform histogram equalization to an image",
3351       "-evaluate operator value",
3352       "                     evaluate an arithmetic, relational, or logical expression",
3353       "-extent geometry     set the image size",
3354       "-extract geometry    extract area from image",
3355       "-fft                 implements the discrete Fourier transform (DFT)",
3356       "-flip                flip image vertically",
3357       "-floodfill geometry color",
3358       "                     floodfill the image with color",
3359       "-flop                flop image horizontally",
3360       "-frame geometry      surround image with an ornamental border",
3361       "-function name parameters",
3362       "                     apply function over image values",
3363       "-gamma value         level of gamma correction",
3364       "-gaussian-blur geometry",
3365       "                     reduce image noise and reduce detail levels",
3366       "-geometry geometry   preferred size or location of the image",
3367       "-identify            identify the format and characteristics of the image",
3368       "-ift                 implements the inverse discrete Fourier transform (DFT)",
3369       "-implode amount      implode image pixels about the center",
3370       "-lat geometry        local adaptive thresholding",
3371       "-layers method       optimize, merge,  or compare image layers",
3372       "-level value         adjust the level of image contrast",
3373       "-level-colors color,color",
3374       "                     level image with the given colors",
3375       "-linear-stretch geometry",
3376       "                     improve contrast by `stretching with saturation'",
3377       "-liquid-rescale geometry",
3378       "                     rescale image with seam-carving",
3379       "-median geometry     apply a median filter to the image",
3380       "-mode geometry       make each pixel the 'predominant color' of the neighborhood",
3381       "-modulate value      vary the brightness, saturation, and hue",
3382       "-monochrome          transform image to black and white",
3383       "-morphology method kernel",
3384       "                     apply a morphology method to the image",
3385       "-motion-blur geometry",
3386       "                     simulate motion blur",
3387       "-negate              replace every pixel with its complementary color ",
3388       "-noise geometry      add or reduce noise in an image",
3389       "-normalize           transform image to span the full range of colors",
3390       "-opaque color        change this color to the fill color",
3391       "-ordered-dither NxN",
3392       "                     add a noise pattern to the image with specific",
3393       "                     amplitudes",
3394       "-paint radius        simulate an oil painting",
3395       "-polaroid angle      simulate a Polaroid picture",
3396       "-posterize levels    reduce the image to a limited number of color levels",
3397       "-profile filename    add, delete, or apply an image profile",
3398       "-quantize colorspace reduce colors in this colorspace",
3399       "-radial-blur angle   radial blur the image",
3400       "-raise value         lighten/darken image edges to create a 3-D effect",
3401       "-random-threshold low,high",
3402       "                     random threshold the image",
3403       "-region geometry     apply options to a portion of the image",
3404       "-render              render vector graphics",
3405       "-repage geometry     size and location of an image canvas",
3406       "-resample geometry   change the resolution of an image",
3407       "-resize geometry     resize the image",
3408       "-roll geometry       roll an image vertically or horizontally",
3409       "-rotate degrees      apply Paeth rotation to the image",
3410       "-sample geometry     scale image with pixel sampling",
3411       "-scale geometry      scale the image",
3412       "-segment values      segment an image",
3413       "-selective-blur geometry",
3414       "                     selectively blur pixels within a contrast threshold",
3415       "-sepia-tone threshold",
3416       "                     simulate a sepia-toned photo",
3417       "-set property value  set an image property",
3418       "-shade degrees       shade the image using a distant light source",
3419       "-shadow geometry     simulate an image shadow",
3420       "-sharpen geometry    sharpen the image",
3421       "-shave geometry      shave pixels from the image edges",
3422       "-shear geometry      slide one edge of the image along the X or Y axis",
3423       "-sigmoidal-contrast geometry",
3424       "                     increase the contrast without saturating highlights or shadows",
3425       "-sketch geometry     simulate a pencil sketch",
3426       "-solarize threshold  negate all pixels above the threshold level",
3427       "-sparse-color method args",
3428       "                     fill in a image based on a few color points",
3429       "-splice geometry     splice the background color into the image",
3430       "-spread radius       displace image pixels by a random amount",
3431       "-statistic type radius",
3432       "                     replace each pixel with corresponding statistic from the neighborhood",
3433       "-strip               strip image of all profiles and comments",
3434       "-swirl degrees       swirl image pixels about the center",
3435       "-threshold value     threshold the image",
3436       "-thumbnail geometry  create a thumbnail of the image",
3437       "-tile filename       tile image when filling a graphic primitive",
3438       "-tint value          tint the image with the fill color",
3439       "-transform           affine transform image",
3440       "-transparent color   make this color transparent within the image",
3441       "-transpose           flip image vertically and rotate 90 degrees",
3442       "-transverse          flop image horizontally and rotate 270 degrees",
3443       "-trim                trim image edges",
3444       "-type type           image type",
3445       "-unique-colors       discard all but one of any pixel color",
3446       "-unsharp geometry    sharpen the image",
3447       "-vignette geometry   soften the edges of the image in vignette style",
3448       "-wave geometry       alter an image along a sine wave",
3449       "-white-threshold value",
3450       "                     force all pixels above the threshold into white",
3451       (char *) NULL
3452     },
3453     *sequence_operators[]=
3454     {
3455       "-append              append an image sequence",
3456       "-clut                apply a color lookup table to the image",
3457       "-coalesce            merge a sequence of images",
3458       "-combine             combine a sequence of images",
3459       "-composite           composite image",
3460       "-crop geometry       cut out a rectangular region of the image",
3461       "-deconstruct         break down an image sequence into constituent parts",
3462       "-evaluate-sequence operator",
3463       "                     evaluate an arithmetic, relational, or logical expression",
3464       "-flatten             flatten a sequence of images",
3465       "-fx expression       apply mathematical expression to an image channel(s)",
3466       "-hald-clut           apply a Hald color lookup table to the image",
3467       "-morph value         morph an image sequence",
3468       "-mosaic              create a mosaic from an image sequence",
3469       "-print string        interpret string and print to console",
3470       "-process arguments   process the image with a custom image filter",
3471       "-separate            separate an image channel into a grayscale image",
3472       "-smush geometry      smush an image sequence together",
3473       "-write filename      write images to this file",
3474       (char *) NULL
3475     },
3476     *settings[]=
3477     {
3478       "-adjoin              join images into a single multi-image file",
3479       "-affine matrix       affine transform matrix",
3480       "-alpha option        activate, deactivate, reset, or set the alpha channel",
3481       "-antialias           remove pixel-aliasing",
3482       "-authenticate password",
3483       "                     decipher image with this password",
3484       "-attenuate value     lessen (or intensify) when adding noise to an image",
3485       "-background color    background color",
3486       "-bias value          add bias when convolving an image",
3487       "-black-point-compensation",
3488       "                     use black point compensation",
3489       "-blue-primary point  chromaticity blue primary point",
3490       "-bordercolor color   border color",
3491       "-caption string      assign a caption to an image",
3492       "-channel type        apply option to select image channels",
3493       "-colors value        preferred number of colors in the image",
3494       "-colorspace type     alternate image colorspace",
3495       "-comment string      annotate image with comment",
3496       "-compose operator    set image composite operator",
3497       "-compress type       type of pixel compression when writing the image",
3498       "-define format:option",
3499       "                     define one or more image format options",
3500       "-delay value         display the next image after pausing",
3501       "-density geometry    horizontal and vertical density of the image",
3502       "-depth value         image depth",
3503       "-direction type      render text right-to-left or left-to-right",
3504       "-display server      get image or font from this X server",
3505       "-dispose method      layer disposal method",
3506       "-dither method       apply error diffusion to image",
3507       "-encoding type       text encoding type",
3508       "-endian type         endianness (MSB or LSB) of the image",
3509       "-family name         render text with this font family",
3510       "-fill color          color to use when filling a graphic primitive",
3511       "-filter type         use this filter when resizing an image",
3512       "-font name           render text with this font",
3513       "-format \"string\"     output formatted image characteristics",
3514       "-fuzz distance       colors within this distance are considered equal",
3515       "-gravity type        horizontal and vertical text placement",
3516       "-green-primary point chromaticity green primary point",
3517       "-intent type         type of rendering intent when managing the image color",
3518       "-interlace type      type of image interlacing scheme",
3519       "-interline-spacing value",
3520       "                     set the space between two text lines",
3521       "-interpolate method  pixel color interpolation method",
3522       "-interword-spacing value",
3523       "                     set the space between two words",
3524       "-kerning value       set the space between two letters",
3525       "-label string        assign a label to an image",
3526       "-limit type value    pixel cache resource limit",
3527       "-loop iterations     add Netscape loop extension to your GIF animation",
3528       "-mask filename       associate a mask with the image",
3529       "-mattecolor color    frame color",
3530       "-monitor             monitor progress",
3531       "-orient type         image orientation",
3532       "-page geometry       size and location of an image canvas (setting)",
3533       "-ping                efficiently determine image attributes",
3534       "-pointsize value     font point size",
3535       "-precision value     maximum number of significant digits to print",
3536       "-preview type        image preview type",
3537       "-quality value       JPEG/MIFF/PNG compression level",
3538       "-quiet               suppress all warning messages",
3539       "-red-primary point   chromaticity red primary point",
3540       "-regard-warnings     pay attention to warning messages",
3541       "-remap filename      transform image colors to match this set of colors",
3542       "-respect-parentheses settings remain in effect until parenthesis boundary",
3543       "-sampling-factor geometry",
3544       "                     horizontal and vertical sampling factor",
3545       "-scene value         image scene number",
3546       "-seed value          seed a new sequence of pseudo-random numbers",
3547       "-size geometry       width and height of image",
3548       "-stretch type        render text with this font stretch",
3549       "-stroke color        graphic primitive stroke color",
3550       "-strokewidth value   graphic primitive stroke width",
3551       "-style type          render text with this font style",
3552       "-synchronize         synchronize image to storage device",
3553       "-taint               declare the image as modified",
3554       "-texture filename    name of texture to tile onto the image background",
3555       "-tile-offset geometry",
3556       "                     tile offset",
3557       "-treedepth value     color tree depth",
3558       "-transparent-color color",
3559       "                     transparent color",
3560       "-undercolor color    annotation bounding box color",
3561       "-units type          the units of image resolution",
3562       "-verbose             print detailed information about the image",
3563       "-view                FlashPix viewing transforms",
3564       "-virtual-pixel method",
3565       "                     virtual pixel access method",
3566       "-weight type         render text with this font weight",
3567       "-white-point point   chromaticity white point",
3568       (char *) NULL
3569     },
3570     *stack_operators[]=
3571     {
3572       "-delete indexes      delete the image from the image sequence",
3573       "-duplicate count,indexes",
3574       "                     duplicate an image one or more times",
3575       "-insert index        insert last image into the image sequence",
3576       "-reverse             reverse image sequence",
3577       "-swap indexes        swap two images in the image sequence",
3578       (char *) NULL
3579     };
3580
3581   const char
3582     **p;
3583
3584   (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
3585   (void) printf("Copyright: %s\n",GetMagickCopyright());
3586   (void) printf("Features: %s\n\n",GetMagickFeatures());
3587   (void) printf("Usage: %s [options ...] file [ [options ...] file ...]\n",
3588     GetClientName());
3589   (void) printf("\nImage Settings:\n");
3590   for (p=settings; *p != (char *) NULL; p++)
3591     (void) printf("  %s\n",*p);
3592   (void) printf("\nImage Operators:\n");
3593   for (p=operators; *p != (char *) NULL; p++)
3594     (void) printf("  %s\n",*p);
3595   (void) printf("\nImage Sequence Operators:\n");
3596   for (p=sequence_operators; *p != (char *) NULL; p++)
3597     (void) printf("  %s\n",*p);
3598   (void) printf("\nImage Stack Operators:\n");
3599   for (p=stack_operators; *p != (char *) NULL; p++)
3600     (void) printf("  %s\n",*p);
3601   (void) printf("\nMiscellaneous Options:\n");
3602   for (p=miscellaneous; *p != (char *) NULL; p++)
3603     (void) printf("  %s\n",*p);
3604   (void) printf(
3605     "\nBy default, the image format of `file' is determined by its magic\n");
3606   (void) printf(
3607     "number.  To specify a particular image format, precede the filename\n");
3608   (void) printf(
3609     "with an image format name and a colon (i.e. ps:image) or specify the\n");
3610   (void) printf(
3611     "image type as the filename suffix (i.e. image.ps).  Specify 'file' as\n");
3612   (void) printf("'-' for standard input or output.\n");
3613   return(MagickFalse);
3614 }
3615
3616 WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
3617   int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
3618 {
3619 #define DestroyMogrify() \
3620 { \
3621   if (format != (char *) NULL) \
3622     format=DestroyString(format); \
3623   if (path != (char *) NULL) \
3624     path=DestroyString(path); \
3625   DestroyImageStack(); \
3626   for (i=0; i < (ssize_t) argc; i++) \
3627     argv[i]=DestroyString(argv[i]); \
3628   argv=(char **) RelinquishMagickMemory(argv); \
3629 }
3630 #define ThrowMogrifyException(asperity,tag,option) \
3631 { \
3632   (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
3633     option); \
3634   DestroyMogrify(); \
3635   return(MagickFalse); \
3636 }
3637 #define ThrowMogrifyInvalidArgumentException(option,argument) \
3638 { \
3639   (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
3640     "InvalidArgument","`%s': %s",argument,option); \
3641   DestroyMogrify(); \
3642   return(MagickFalse); \
3643 }
3644
3645   char
3646     *format,
3647     *option,
3648     *path;
3649
3650   Image
3651     *image;
3652
3653   ImageStack
3654     image_stack[MaxImageStackDepth+1];
3655
3656   MagickBooleanType
3657     global_colormap;
3658
3659   MagickBooleanType
3660     fire,
3661     pend,
3662     respect_parenthesis;
3663
3664   MagickStatusType
3665     status;
3666
3667   register ssize_t
3668     i;
3669
3670   ssize_t
3671     j,
3672     k;
3673
3674   /*
3675     Set defaults.
3676   */
3677   assert(image_info != (ImageInfo *) NULL);
3678   assert(image_info->signature == MagickSignature);
3679   if (image_info->debug != MagickFalse)
3680     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
3681   assert(exception != (ExceptionInfo *) NULL);
3682   if (argc == 2)
3683     {
3684       option=argv[1];
3685       if ((LocaleCompare("version",option+1) == 0) ||
3686           (LocaleCompare("-version",option+1) == 0))
3687         {
3688           (void) FormatLocaleFile(stdout,"Version: %s\n",
3689             GetMagickVersion((size_t *) NULL));
3690           (void) FormatLocaleFile(stdout,"Copyright: %s\n",
3691             GetMagickCopyright());
3692           (void) FormatLocaleFile(stdout,"Features: %s\n\n",
3693             GetMagickFeatures());
3694           return(MagickFalse);
3695         }
3696     }
3697   if (argc < 2)
3698     return(MogrifyUsage());
3699   format=(char *) NULL;
3700   path=(char *) NULL;
3701   global_colormap=MagickFalse;
3702   k=0;
3703   j=1;
3704   NewImageStack();
3705   option=(char *) NULL;
3706   pend=MagickFalse;
3707   respect_parenthesis=MagickFalse;
3708   status=MagickTrue;
3709   /*
3710     Parse command line.
3711   */
3712   ReadCommandlLine(argc,&argv);
3713   status=ExpandFilenames(&argc,&argv);
3714   if (status == MagickFalse)
3715     ThrowMogrifyException(ResourceLimitError,"MemoryAllocationFailed",
3716       GetExceptionMessage(errno));
3717   for (i=1; i < (ssize_t) argc; i++)
3718   {
3719     option=argv[i];
3720     if (LocaleCompare(option,"(") == 0)
3721       {
3722         FireImageStack(MagickFalse,MagickTrue,pend);
3723         if (k == MaxImageStackDepth)
3724           ThrowMogrifyException(OptionError,"ParenthesisNestedTooDeeply",
3725             option);
3726         PushImageStack();
3727         continue;
3728       }
3729     if (LocaleCompare(option,")") == 0)
3730       {
3731         FireImageStack(MagickFalse,MagickTrue,MagickTrue);
3732         if (k == 0)
3733           ThrowMogrifyException(OptionError,"UnableToParseExpression",option);
3734         PopImageStack();
3735         continue;
3736       }
3737     if (IsCommandOption(option) == MagickFalse)
3738       {
3739         char
3740           backup_filename[MaxTextExtent],
3741           *filename;
3742
3743         Image
3744           *images;
3745
3746         /*
3747           Option is a file name: begin by reading image from specified file.
3748         */
3749         FireImageStack(MagickFalse,MagickFalse,pend);
3750         filename=argv[i];
3751         if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
3752           filename=argv[++i];
3753         (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
3754         images=ReadImages(image_info,exception);
3755         status&=(images != (Image *) NULL) &&
3756           (exception->severity < ErrorException);
3757         if (images == (Image *) NULL)
3758           continue;
3759         if (format != (char *) NULL)
3760           (void) CopyMagickString(images->filename,images->magick_filename,
3761             MaxTextExtent);
3762         if (path != (char *) NULL)
3763           {
3764             GetPathComponent(option,TailPath,filename);
3765             (void) FormatLocaleString(images->filename,MaxTextExtent,"%s%c%s",
3766               path,*DirectorySeparator,filename);
3767           }
3768         if (format != (char *) NULL)
3769           AppendImageFormat(format,images->filename);
3770         AppendImageStack(images);
3771         FinalizeImageSettings(image_info,image,MagickFalse);
3772         if (global_colormap != MagickFalse)
3773           {
3774             QuantizeInfo
3775               *quantize_info;
3776
3777             quantize_info=AcquireQuantizeInfo(image_info);
3778             (void) RemapImages(quantize_info,images,(Image *) NULL,exception);
3779             quantize_info=DestroyQuantizeInfo(quantize_info);
3780           }
3781         *backup_filename='\0';
3782         if ((LocaleCompare(image->filename,"-") != 0) &&
3783             (IsPathWritable(image->filename) != MagickFalse))
3784           {
3785             register ssize_t
3786               i;
3787
3788             /*
3789               Rename image file as backup.
3790             */
3791             (void) CopyMagickString(backup_filename,image->filename,
3792               MaxTextExtent);
3793             for (i=0; i < 6; i++)
3794             {
3795               (void) ConcatenateMagickString(backup_filename,"~",MaxTextExtent);
3796               if (IsPathAccessible(backup_filename) == MagickFalse)
3797                 break;
3798             }
3799             if ((IsPathAccessible(backup_filename) != MagickFalse) ||
3800                 (rename_utf8(image->filename,backup_filename) != 0))
3801               *backup_filename='\0';
3802           }
3803         /*
3804           Write transmogrified image to disk.
3805         */
3806         image_info->synchronize=MagickTrue;
3807         status&=WriteImages(image_info,image,image->filename,exception);
3808         if ((status == MagickFalse) && (*backup_filename != '\0'))
3809           (void) remove_utf8(backup_filename);
3810         RemoveAllImageStack();
3811         continue;
3812       }
3813     pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
3814     switch (*(option+1))
3815     {
3816       case 'a':
3817       {
3818         if (LocaleCompare("adaptive-blur",option+1) == 0)
3819           {
3820             i++;
3821             if (i == (ssize_t) argc)
3822               ThrowMogrifyException(OptionError,"MissingArgument",option);
3823             if (IsGeometry(argv[i]) == MagickFalse)
3824               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3825             break;
3826           }
3827         if (LocaleCompare("adaptive-resize",option+1) == 0)
3828           {
3829             i++;
3830             if (i == (ssize_t) argc)
3831               ThrowMogrifyException(OptionError,"MissingArgument",option);
3832             if (IsGeometry(argv[i]) == MagickFalse)
3833               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3834             break;
3835           }
3836         if (LocaleCompare("adaptive-sharpen",option+1) == 0)
3837           {
3838             i++;
3839             if (i == (ssize_t) argc)
3840               ThrowMogrifyException(OptionError,"MissingArgument",option);
3841             if (IsGeometry(argv[i]) == MagickFalse)
3842               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3843             break;
3844           }
3845         if (LocaleCompare("affine",option+1) == 0)
3846           {
3847             if (*option == '+')
3848               break;
3849             i++;
3850             if (i == (ssize_t) argc)
3851               ThrowMogrifyException(OptionError,"MissingArgument",option);
3852             break;
3853           }
3854         if (LocaleCompare("alpha",option+1) == 0)
3855           {
3856             ssize_t
3857               type;
3858
3859             if (*option == '+')
3860               break;
3861             i++;
3862             if (i == (ssize_t) argc)
3863               ThrowMogrifyException(OptionError,"MissingArgument",option);
3864             type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
3865             if (type < 0)
3866               ThrowMogrifyException(OptionError,"UnrecognizedAlphaChannelType",
3867                 argv[i]);
3868             break;
3869           }
3870         if (LocaleCompare("annotate",option+1) == 0)
3871           {
3872             if (*option == '+')
3873               break;
3874             i++;
3875             if (i == (ssize_t) argc)
3876               ThrowMogrifyException(OptionError,"MissingArgument",option);
3877             if (IsGeometry(argv[i]) == MagickFalse)
3878               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3879             if (i == (ssize_t) argc)
3880               ThrowMogrifyException(OptionError,"MissingArgument",option);
3881             i++;
3882             break;
3883           }
3884         if (LocaleCompare("antialias",option+1) == 0)
3885           break;
3886         if (LocaleCompare("append",option+1) == 0)
3887           break;
3888         if (LocaleCompare("attenuate",option+1) == 0)
3889           {
3890             if (*option == '+')
3891               break;
3892             i++;
3893             if (i == (ssize_t) (argc-1))
3894               ThrowMogrifyException(OptionError,"MissingArgument",option);
3895             if (IsGeometry(argv[i]) == MagickFalse)
3896               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3897             break;
3898           }
3899         if (LocaleCompare("authenticate",option+1) == 0)
3900           {
3901             if (*option == '+')
3902               break;
3903             i++;
3904             if (i == (ssize_t) argc)
3905               ThrowMogrifyException(OptionError,"MissingArgument",option);
3906             break;
3907           }
3908         if (LocaleCompare("auto-gamma",option+1) == 0)
3909           break;
3910         if (LocaleCompare("auto-level",option+1) == 0)
3911           break;
3912         if (LocaleCompare("auto-orient",option+1) == 0)
3913           break;
3914         if (LocaleCompare("average",option+1) == 0)
3915           break;
3916         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
3917       }
3918       case 'b':
3919       {
3920         if (LocaleCompare("background",option+1) == 0)
3921           {
3922             if (*option == '+')
3923               break;
3924             i++;
3925             if (i == (ssize_t) argc)
3926               ThrowMogrifyException(OptionError,"MissingArgument",option);
3927             break;
3928           }
3929         if (LocaleCompare("bias",option+1) == 0)
3930           {
3931             if (*option == '+')
3932               break;
3933             i++;
3934             if (i == (ssize_t) (argc-1))
3935               ThrowMogrifyException(OptionError,"MissingArgument",option);
3936             if (IsGeometry(argv[i]) == MagickFalse)
3937               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3938             break;
3939           }
3940         if (LocaleCompare("black-point-compensation",option+1) == 0)
3941           break;
3942         if (LocaleCompare("black-threshold",option+1) == 0)
3943           {
3944             if (*option == '+')
3945               break;
3946             i++;
3947             if (i == (ssize_t) argc)
3948               ThrowMogrifyException(OptionError,"MissingArgument",option);
3949             if (IsGeometry(argv[i]) == MagickFalse)
3950               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3951             break;
3952           }
3953         if (LocaleCompare("blue-primary",option+1) == 0)
3954           {
3955             if (*option == '+')
3956               break;
3957             i++;
3958             if (i == (ssize_t) argc)
3959               ThrowMogrifyException(OptionError,"MissingArgument",option);
3960             if (IsGeometry(argv[i]) == MagickFalse)
3961               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3962             break;
3963           }
3964         if (LocaleCompare("blue-shift",option+1) == 0)
3965           {
3966             i++;
3967             if (i == (ssize_t) argc)
3968               ThrowMogrifyException(OptionError,"MissingArgument",option);
3969             if (IsGeometry(argv[i]) == MagickFalse)
3970               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3971             break;
3972           }
3973         if (LocaleCompare("blur",option+1) == 0)
3974           {
3975             i++;
3976             if (i == (ssize_t) argc)
3977               ThrowMogrifyException(OptionError,"MissingArgument",option);
3978             if (IsGeometry(argv[i]) == MagickFalse)
3979               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3980             break;
3981           }
3982         if (LocaleCompare("border",option+1) == 0)
3983           {
3984             if (*option == '+')
3985               break;
3986             i++;
3987             if (i == (ssize_t) argc)
3988               ThrowMogrifyException(OptionError,"MissingArgument",option);
3989             if (IsGeometry(argv[i]) == MagickFalse)
3990               ThrowMogrifyInvalidArgumentException(option,argv[i]);
3991             break;
3992           }
3993         if (LocaleCompare("bordercolor",option+1) == 0)
3994           {
3995             if (*option == '+')
3996               break;
3997             i++;
3998             if (i == (ssize_t) argc)
3999               ThrowMogrifyException(OptionError,"MissingArgument",option);
4000             break;
4001           }
4002         if (LocaleCompare("box",option+1) == 0)
4003           {
4004             if (*option == '+')
4005               break;
4006             i++;
4007             if (i == (ssize_t) argc)
4008               ThrowMogrifyException(OptionError,"MissingArgument",option);
4009             break;
4010           }
4011         if (LocaleCompare("brightness-contrast",option+1) == 0)
4012           {
4013             i++;
4014             if (i == (ssize_t) argc)
4015               ThrowMogrifyException(OptionError,"MissingArgument",option);
4016             if (IsGeometry(argv[i]) == MagickFalse)
4017               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4018             break;
4019           }
4020         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4021       }
4022       case 'c':
4023       {
4024         if (LocaleCompare("cache",option+1) == 0)
4025           {
4026             if (*option == '+')
4027               break;
4028             i++;
4029             if (i == (ssize_t) argc)
4030               ThrowMogrifyException(OptionError,"MissingArgument",option);
4031             if (IsGeometry(argv[i]) == MagickFalse)
4032               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4033             break;
4034           }
4035         if (LocaleCompare("caption",option+1) == 0)
4036           {
4037             if (*option == '+')
4038               break;
4039             i++;
4040             if (i == (ssize_t) argc)
4041               ThrowMogrifyException(OptionError,"MissingArgument",option);
4042             break;
4043           }
4044         if (LocaleCompare("channel",option+1) == 0)
4045           {
4046             ssize_t
4047               channel;
4048
4049             if (*option == '+')
4050               break;
4051             i++;
4052             if (i == (ssize_t) (argc-1))
4053               ThrowMogrifyException(OptionError,"MissingArgument",option);
4054             channel=ParseChannelOption(argv[i]);
4055             if (channel < 0)
4056               ThrowMogrifyException(OptionError,"UnrecognizedChannelType",
4057                 argv[i]);
4058             break;
4059           }
4060         if (LocaleCompare("cdl",option+1) == 0)
4061           {
4062             if (*option == '+')
4063               break;
4064             i++;
4065             if (i == (ssize_t) (argc-1))
4066               ThrowMogrifyException(OptionError,"MissingArgument",option);
4067             break;
4068           }
4069         if (LocaleCompare("charcoal",option+1) == 0)
4070           {
4071             if (*option == '+')
4072               break;
4073             i++;
4074             if (i == (ssize_t) argc)
4075               ThrowMogrifyException(OptionError,"MissingArgument",option);
4076             if (IsGeometry(argv[i]) == MagickFalse)
4077               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4078             break;
4079           }
4080         if (LocaleCompare("chop",option+1) == 0)
4081           {
4082             if (*option == '+')
4083               break;
4084             i++;
4085             if (i == (ssize_t) argc)
4086               ThrowMogrifyException(OptionError,"MissingArgument",option);
4087             if (IsGeometry(argv[i]) == MagickFalse)
4088               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4089             break;
4090           }
4091         if (LocaleCompare("clamp",option+1) == 0)
4092           break;
4093         if (LocaleCompare("clip",option+1) == 0)
4094           break;
4095         if (LocaleCompare("clip-mask",option+1) == 0)
4096           {
4097             if (*option == '+')
4098               break;
4099             i++;
4100             if (i == (ssize_t) argc)
4101               ThrowMogrifyException(OptionError,"MissingArgument",option);
4102             break;
4103           }
4104         if (LocaleCompare("clut",option+1) == 0)
4105           break;
4106         if (LocaleCompare("coalesce",option+1) == 0)
4107           break;
4108         if (LocaleCompare("colorize",option+1) == 0)
4109           {
4110             if (*option == '+')
4111               break;
4112             i++;
4113             if (i == (ssize_t) argc)
4114               ThrowMogrifyException(OptionError,"MissingArgument",option);
4115             if (IsGeometry(argv[i]) == MagickFalse)
4116               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4117             break;
4118           }
4119         if (LocaleCompare("color-matrix",option+1) == 0)
4120           {
4121             KernelInfo
4122               *kernel_info;
4123
4124             if (*option == '+')
4125               break;
4126             i++;
4127             if (i == (ssize_t) (argc-1))
4128               ThrowMogrifyException(OptionError,"MissingArgument",option);
4129             kernel_info=AcquireKernelInfo(argv[i]);
4130             if (kernel_info == (KernelInfo *) NULL)
4131               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4132             kernel_info=DestroyKernelInfo(kernel_info);
4133             break;
4134           }
4135         if (LocaleCompare("colors",option+1) == 0)
4136           {
4137             if (*option == '+')
4138               break;
4139             i++;
4140             if (i == (ssize_t) argc)
4141               ThrowMogrifyException(OptionError,"MissingArgument",option);
4142             if (IsGeometry(argv[i]) == MagickFalse)
4143               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4144             break;
4145           }
4146         if (LocaleCompare("colorspace",option+1) == 0)
4147           {
4148             ssize_t
4149               colorspace;
4150
4151             if (*option == '+')
4152               break;
4153             i++;
4154             if (i == (ssize_t) argc)
4155               ThrowMogrifyException(OptionError,"MissingArgument",option);
4156             colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
4157               argv[i]);
4158             if (colorspace < 0)
4159               ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
4160                 argv[i]);
4161             break;
4162           }
4163         if (LocaleCompare("combine",option+1) == 0)
4164           break;
4165         if (LocaleCompare("comment",option+1) == 0)
4166           {
4167             if (*option == '+')
4168               break;
4169             i++;
4170             if (i == (ssize_t) argc)
4171               ThrowMogrifyException(OptionError,"MissingArgument",option);
4172             break;
4173           }
4174         if (LocaleCompare("composite",option+1) == 0)
4175           break;
4176         if (LocaleCompare("compress",option+1) == 0)
4177           {
4178             ssize_t
4179               compress;
4180
4181             if (*option == '+')
4182               break;
4183             i++;
4184             if (i == (ssize_t) argc)
4185               ThrowMogrifyException(OptionError,"MissingArgument",option);
4186             compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
4187               argv[i]);
4188             if (compress < 0)
4189               ThrowMogrifyException(OptionError,"UnrecognizedImageCompression",
4190                 argv[i]);
4191             break;
4192           }
4193         if (LocaleCompare("concurrent",option+1) == 0)
4194           break;
4195         if (LocaleCompare("contrast",option+1) == 0)
4196           break;
4197         if (LocaleCompare("contrast-stretch",option+1) == 0)
4198           {
4199             i++;
4200             if (i == (ssize_t) argc)
4201               ThrowMogrifyException(OptionError,"MissingArgument",option);
4202             if (IsGeometry(argv[i]) == MagickFalse)
4203               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4204             break;
4205           }
4206         if (LocaleCompare("convolve",option+1) == 0)
4207           {
4208             KernelInfo
4209               *kernel_info;
4210
4211             if (*option == '+')
4212               break;
4213             i++;
4214             if (i == (ssize_t) argc)
4215               ThrowMogrifyException(OptionError,"MissingArgument",option);
4216             kernel_info=AcquireKernelInfo(argv[i]);
4217             if (kernel_info == (KernelInfo *) NULL)
4218               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4219             kernel_info=DestroyKernelInfo(kernel_info);
4220             break;
4221           }
4222         if (LocaleCompare("crop",option+1) == 0)
4223           {
4224             if (*option == '+')
4225               break;
4226             i++;
4227             if (i == (ssize_t) argc)
4228               ThrowMogrifyException(OptionError,"MissingArgument",option);
4229             if (IsGeometry(argv[i]) == MagickFalse)
4230               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4231             break;
4232           }
4233         if (LocaleCompare("cycle",option+1) == 0)
4234           {
4235             if (*option == '+')
4236               break;
4237             i++;
4238             if (i == (ssize_t) argc)
4239               ThrowMogrifyException(OptionError,"MissingArgument",option);
4240             if (IsGeometry(argv[i]) == MagickFalse)
4241               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4242             break;
4243           }
4244         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4245       }
4246       case 'd':
4247       {
4248         if (LocaleCompare("decipher",option+1) == 0)
4249           {
4250             if (*option == '+')
4251               break;
4252             i++;
4253             if (i == (ssize_t) (argc-1))
4254               ThrowMogrifyException(OptionError,"MissingArgument",option);
4255             break;
4256           }
4257         if (LocaleCompare("deconstruct",option+1) == 0)
4258           break;
4259         if (LocaleCompare("debug",option+1) == 0)
4260           {
4261             ssize_t
4262               event;
4263
4264             if (*option == '+')
4265               break;
4266             i++;
4267             if (i == (ssize_t) argc)
4268               ThrowMogrifyException(OptionError,"MissingArgument",option);
4269             event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
4270             if (event < 0)
4271               ThrowMogrifyException(OptionError,"UnrecognizedEventType",
4272                 argv[i]);
4273             (void) SetLogEventMask(argv[i]);
4274             break;
4275           }
4276         if (LocaleCompare("define",option+1) == 0)
4277           {
4278             i++;
4279             if (i == (ssize_t) argc)
4280               ThrowMogrifyException(OptionError,"MissingArgument",option);
4281             if (*option == '+')
4282               {
4283                 const char
4284                   *define;
4285
4286                 define=GetImageOption(image_info,argv[i]);
4287                 if (define == (const char *) NULL)
4288                   ThrowMogrifyException(OptionError,"NoSuchOption",argv[i]);
4289                 break;
4290               }
4291             break;
4292           }
4293         if (LocaleCompare("delay",option+1) == 0)
4294           {
4295             if (*option == '+')
4296               break;
4297             i++;
4298             if (i == (ssize_t) argc)
4299               ThrowMogrifyException(OptionError,"MissingArgument",option);
4300             if (IsGeometry(argv[i]) == MagickFalse)
4301               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4302             break;
4303           }
4304         if (LocaleCompare("delete",option+1) == 0)
4305           {
4306             if (*option == '+')
4307               break;
4308             i++;
4309             if (i == (ssize_t) (argc-1))
4310               ThrowMogrifyException(OptionError,"MissingArgument",option);
4311             if (IsGeometry(argv[i]) == MagickFalse)
4312               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4313             break;
4314           }
4315         if (LocaleCompare("density",option+1) == 0)
4316           {
4317             if (*option == '+')
4318               break;
4319             i++;
4320             if (i == (ssize_t) argc)
4321               ThrowMogrifyException(OptionError,"MissingArgument",option);
4322             if (IsGeometry(argv[i]) == MagickFalse)
4323               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4324             break;
4325           }
4326         if (LocaleCompare("depth",option+1) == 0)
4327           {
4328             if (*option == '+')
4329               break;
4330             i++;
4331             if (i == (ssize_t) argc)
4332               ThrowMogrifyException(OptionError,"MissingArgument",option);
4333             if (IsGeometry(argv[i]) == MagickFalse)
4334               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4335             break;
4336           }
4337         if (LocaleCompare("deskew",option+1) == 0)
4338           {
4339             if (*option == '+')
4340               break;
4341             i++;
4342             if (i == (ssize_t) argc)
4343               ThrowMogrifyException(OptionError,"MissingArgument",option);
4344             if (IsGeometry(argv[i]) == MagickFalse)
4345               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4346             break;
4347           }
4348         if (LocaleCompare("despeckle",option+1) == 0)
4349           break;
4350         if (LocaleCompare("dft",option+1) == 0)
4351           break;
4352         if (LocaleCompare("direction",option+1) == 0)
4353           {
4354             ssize_t
4355               direction;
4356
4357             if (*option == '+')
4358               break;
4359             i++;
4360             if (i == (ssize_t) argc)
4361               ThrowMogrifyException(OptionError,"MissingArgument",option);
4362             direction=ParseCommandOption(MagickDirectionOptions,MagickFalse,
4363               argv[i]);
4364             if (direction < 0)
4365               ThrowMogrifyException(OptionError,"UnrecognizedDirectionType",
4366                 argv[i]);
4367             break;
4368           }
4369         if (LocaleCompare("display",option+1) == 0)
4370           {
4371             if (*option == '+')
4372               break;
4373             i++;
4374             if (i == (ssize_t) argc)
4375               ThrowMogrifyException(OptionError,"MissingArgument",option);
4376             break;
4377           }
4378         if (LocaleCompare("dispose",option+1) == 0)
4379           {
4380             ssize_t
4381               dispose;
4382
4383             if (*option == '+')
4384               break;
4385             i++;
4386             if (i == (ssize_t) argc)
4387               ThrowMogrifyException(OptionError,"MissingArgument",option);
4388             dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
4389             if (dispose < 0)
4390               ThrowMogrifyException(OptionError,"UnrecognizedDisposeMethod",
4391                 argv[i]);
4392             break;
4393           }
4394         if (LocaleCompare("distort",option+1) == 0)
4395           {
4396             ssize_t
4397               op;
4398
4399             i++;
4400             if (i == (ssize_t) argc)
4401               ThrowMogrifyException(OptionError,"MissingArgument",option);
4402             op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
4403             if (op < 0)
4404               ThrowMogrifyException(OptionError,"UnrecognizedDistortMethod",
4405                 argv[i]);
4406             i++;
4407             if (i == (ssize_t) (argc-1))
4408               ThrowMogrifyException(OptionError,"MissingArgument",option);
4409             break;
4410           }
4411         if (LocaleCompare("dither",option+1) == 0)
4412           {
4413             ssize_t
4414               method;
4415
4416             if (*option == '+')
4417               break;
4418             i++;
4419             if (i == (ssize_t) argc)
4420               ThrowMogrifyException(OptionError,"MissingArgument",option);
4421             method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
4422             if (method < 0)
4423               ThrowMogrifyException(OptionError,"UnrecognizedDitherMethod",
4424                 argv[i]);
4425             break;
4426           }
4427         if (LocaleCompare("draw",option+1) == 0)
4428           {
4429             if (*option == '+')
4430               break;
4431             i++;
4432             if (i == (ssize_t) argc)
4433               ThrowMogrifyException(OptionError,"MissingArgument",option);
4434             break;
4435           }
4436         if (LocaleCompare("duplicate",option+1) == 0)
4437           {
4438             if (*option == '+')
4439               break;
4440             i++;
4441             if (i == (ssize_t) (argc-1))
4442               ThrowMogrifyException(OptionError,"MissingArgument",option);
4443             if (IsGeometry(argv[i]) == MagickFalse)
4444               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4445             break;
4446           }
4447         if (LocaleCompare("duration",option+1) == 0)
4448           {
4449             if (*option == '+')
4450               break;
4451             i++;
4452             if (i == (ssize_t) (argc-1))
4453               ThrowMogrifyException(OptionError,"MissingArgument",option);
4454             if (IsGeometry(argv[i]) == MagickFalse)
4455               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4456             break;
4457           }
4458         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4459       }
4460       case 'e':
4461       {
4462         if (LocaleCompare("edge",option+1) == 0)
4463           {
4464             if (*option == '+')
4465               break;
4466             i++;
4467             if (i == (ssize_t) argc)
4468               ThrowMogrifyException(OptionError,"MissingArgument",option);
4469             if (IsGeometry(argv[i]) == MagickFalse)
4470               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4471             break;
4472           }
4473         if (LocaleCompare("emboss",option+1) == 0)
4474           {
4475             if (*option == '+')
4476               break;
4477             i++;
4478             if (i == (ssize_t) argc)
4479               ThrowMogrifyException(OptionError,"MissingArgument",option);
4480             if (IsGeometry(argv[i]) == MagickFalse)
4481               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4482             break;
4483           }
4484         if (LocaleCompare("encipher",option+1) == 0)
4485           {
4486             if (*option == '+')
4487               break;
4488             i++;
4489             if (i == (ssize_t) argc)
4490               ThrowMogrifyException(OptionError,"MissingArgument",option);
4491             break;
4492           }
4493         if (LocaleCompare("encoding",option+1) == 0)
4494           {
4495             if (*option == '+')
4496               break;
4497             i++;
4498             if (i == (ssize_t) argc)
4499               ThrowMogrifyException(OptionError,"MissingArgument",option);
4500             break;
4501           }
4502         if (LocaleCompare("endian",option+1) == 0)
4503           {
4504             ssize_t
4505               endian;
4506
4507             if (*option == '+')
4508               break;
4509             i++;
4510             if (i == (ssize_t) argc)
4511               ThrowMogrifyException(OptionError,"MissingArgument",option);
4512             endian=ParseCommandOption(MagickEndianOptions,MagickFalse,argv[i]);
4513             if (endian < 0)
4514               ThrowMogrifyException(OptionError,"UnrecognizedEndianType",
4515                 argv[i]);
4516             break;
4517           }
4518         if (LocaleCompare("enhance",option+1) == 0)
4519           break;
4520         if (LocaleCompare("equalize",option+1) == 0)
4521           break;
4522         if (LocaleCompare("evaluate",option+1) == 0)
4523           {
4524             ssize_t
4525               op;
4526
4527             if (*option == '+')
4528               break;
4529             i++;
4530             if (i == (ssize_t) argc)
4531               ThrowMogrifyException(OptionError,"MissingArgument",option);
4532             op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4533             if (op < 0)
4534               ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4535                 argv[i]);
4536             i++;
4537             if (i == (ssize_t) (argc-1))
4538               ThrowMogrifyException(OptionError,"MissingArgument",option);
4539             if (IsGeometry(argv[i]) == MagickFalse)
4540               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4541             break;
4542           }
4543         if (LocaleCompare("evaluate-sequence",option+1) == 0)
4544           {
4545             ssize_t
4546               op;
4547
4548             if (*option == '+')
4549               break;
4550             i++;
4551             if (i == (ssize_t) argc)
4552               ThrowMogrifyException(OptionError,"MissingArgument",option);
4553             op=ParseCommandOption(MagickEvaluateOptions,MagickFalse,argv[i]);
4554             if (op < 0)
4555               ThrowMogrifyException(OptionError,"UnrecognizedEvaluateOperator",
4556                 argv[i]);
4557             break;
4558           }
4559         if (LocaleCompare("extent",option+1) == 0)
4560           {
4561             if (*option == '+')
4562               break;
4563             i++;
4564             if (i == (ssize_t) argc)
4565               ThrowMogrifyException(OptionError,"MissingArgument",option);
4566             if (IsGeometry(argv[i]) == MagickFalse)
4567               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4568             break;
4569           }
4570         if (LocaleCompare("extract",option+1) == 0)
4571           {
4572             if (*option == '+')
4573               break;
4574             i++;
4575             if (i == (ssize_t) argc)
4576               ThrowMogrifyException(OptionError,"MissingArgument",option);
4577             if (IsGeometry(argv[i]) == MagickFalse)
4578               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4579             break;
4580           }
4581         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4582       }
4583       case 'f':
4584       {
4585         if (LocaleCompare("family",option+1) == 0)
4586           {
4587             if (*option == '+')
4588               break;
4589             i++;
4590             if (i == (ssize_t) (argc-1))
4591               ThrowMogrifyException(OptionError,"MissingArgument",option);
4592             break;
4593           }
4594         if (LocaleCompare("fill",option+1) == 0)
4595           {
4596             if (*option == '+')
4597               break;
4598             i++;
4599             if (i == (ssize_t) argc)
4600               ThrowMogrifyException(OptionError,"MissingArgument",option);
4601             break;
4602           }
4603         if (LocaleCompare("filter",option+1) == 0)
4604           {
4605             ssize_t
4606               filter;
4607
4608             if (*option == '+')
4609               break;
4610             i++;
4611             if (i == (ssize_t) argc)
4612               ThrowMogrifyException(OptionError,"MissingArgument",option);
4613             filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
4614             if (filter < 0)
4615               ThrowMogrifyException(OptionError,"UnrecognizedImageFilter",
4616                 argv[i]);
4617             break;
4618           }
4619         if (LocaleCompare("flatten",option+1) == 0)
4620           break;
4621         if (LocaleCompare("flip",option+1) == 0)
4622           break;
4623         if (LocaleCompare("flop",option+1) == 0)
4624           break;
4625         if (LocaleCompare("floodfill",option+1) == 0)
4626           {
4627             if (*option == '+')
4628               break;
4629             i++;
4630             if (i == (ssize_t) argc)
4631               ThrowMogrifyException(OptionError,"MissingArgument",option);
4632             if (IsGeometry(argv[i]) == MagickFalse)
4633               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4634             i++;
4635             if (i == (ssize_t) argc)
4636               ThrowMogrifyException(OptionError,"MissingArgument",option);
4637             break;
4638           }
4639         if (LocaleCompare("font",option+1) == 0)
4640           {
4641             if (*option == '+')
4642               break;
4643             i++;
4644             if (i == (ssize_t) argc)
4645               ThrowMogrifyException(OptionError,"MissingArgument",option);
4646             break;
4647           }
4648         if (LocaleCompare("format",option+1) == 0)
4649           {
4650             (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
4651             (void) CloneString(&format,(char *) NULL);
4652             if (*option == '+')
4653               break;
4654             i++;
4655             if (i == (ssize_t) argc)
4656               ThrowMogrifyException(OptionError,"MissingArgument",option);
4657             (void) CloneString(&format,argv[i]);
4658             (void) CopyMagickString(image_info->filename,format,MaxTextExtent);
4659             (void) ConcatenateMagickString(image_info->filename,":",
4660               MaxTextExtent);
4661             (void) SetImageInfo(image_info,0,exception);
4662             if (*image_info->magick == '\0')
4663               ThrowMogrifyException(OptionError,"UnrecognizedImageFormat",
4664                 format);
4665             break;
4666           }
4667         if (LocaleCompare("frame",option+1) == 0)
4668           {
4669             if (*option == '+')
4670               break;
4671             i++;
4672             if (i == (ssize_t) argc)
4673               ThrowMogrifyException(OptionError,"MissingArgument",option);
4674             if (IsGeometry(argv[i]) == MagickFalse)
4675               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4676             break;
4677           }
4678         if (LocaleCompare("function",option+1) == 0)
4679           {
4680             ssize_t
4681               op;
4682
4683             if (*option == '+')
4684               break;
4685             i++;
4686             if (i == (ssize_t) argc)
4687               ThrowMogrifyException(OptionError,"MissingArgument",option);
4688             op=ParseCommandOption(MagickFunctionOptions,MagickFalse,argv[i]);
4689             if (op < 0)
4690               ThrowMogrifyException(OptionError,"UnrecognizedFunction",argv[i]);
4691              i++;
4692              if (i == (ssize_t) (argc-1))
4693                ThrowMogrifyException(OptionError,"MissingArgument",option);
4694             break;
4695           }
4696         if (LocaleCompare("fuzz",option+1) == 0)
4697           {
4698             if (*option == '+')
4699               break;
4700             i++;
4701             if (i == (ssize_t) argc)
4702               ThrowMogrifyException(OptionError,"MissingArgument",option);
4703             if (IsGeometry(argv[i]) == MagickFalse)
4704               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4705             break;
4706           }
4707         if (LocaleCompare("fx",option+1) == 0)
4708           {
4709             if (*option == '+')
4710               break;
4711             i++;
4712             if (i == (ssize_t) (argc-1))
4713               ThrowMogrifyException(OptionError,"MissingArgument",option);
4714             break;
4715           }
4716         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4717       }
4718       case 'g':
4719       {
4720         if (LocaleCompare("gamma",option+1) == 0)
4721           {
4722             i++;
4723             if (i == (ssize_t) argc)
4724               ThrowMogrifyException(OptionError,"MissingArgument",option);
4725             if (IsGeometry(argv[i]) == MagickFalse)
4726               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4727             break;
4728           }
4729         if ((LocaleCompare("gaussian-blur",option+1) == 0) ||
4730             (LocaleCompare("gaussian",option+1) == 0))
4731           {
4732             i++;
4733             if (i == (ssize_t) argc)
4734               ThrowMogrifyException(OptionError,"MissingArgument",option);
4735             if (IsGeometry(argv[i]) == MagickFalse)
4736               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4737             break;
4738           }
4739         if (LocaleCompare("geometry",option+1) == 0)
4740           {
4741             if (*option == '+')
4742               break;
4743             i++;
4744             if (i == (ssize_t) argc)
4745               ThrowMogrifyException(OptionError,"MissingArgument",option);
4746             if (IsGeometry(argv[i]) == MagickFalse)
4747               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4748             break;
4749           }
4750         if (LocaleCompare("gravity",option+1) == 0)
4751           {
4752             ssize_t
4753               gravity;
4754
4755             if (*option == '+')
4756               break;
4757             i++;
4758             if (i == (ssize_t) argc)
4759               ThrowMogrifyException(OptionError,"MissingArgument",option);
4760             gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,argv[i]);
4761             if (gravity < 0)
4762               ThrowMogrifyException(OptionError,"UnrecognizedGravityType",
4763                 argv[i]);
4764             break;
4765           }
4766         if (LocaleCompare("green-primary",option+1) == 0)
4767           {
4768             if (*option == '+')
4769               break;
4770             i++;
4771             if (i == (ssize_t) argc)
4772               ThrowMogrifyException(OptionError,"MissingArgument",option);
4773             if (IsGeometry(argv[i]) == MagickFalse)
4774               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4775             break;
4776           }
4777         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4778       }
4779       case 'h':
4780       {
4781         if (LocaleCompare("hald-clut",option+1) == 0)
4782           break;
4783         if ((LocaleCompare("help",option+1) == 0) ||
4784             (LocaleCompare("-help",option+1) == 0))
4785           return(MogrifyUsage());
4786         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4787       }
4788       case 'i':
4789       {
4790         if (LocaleCompare("identify",option+1) == 0)
4791           break;
4792         if (LocaleCompare("idft",option+1) == 0)
4793           break;
4794         if (LocaleCompare("implode",option+1) == 0)
4795           {
4796             if (*option == '+')
4797               break;
4798             i++;
4799             if (i == (ssize_t) argc)
4800               ThrowMogrifyException(OptionError,"MissingArgument",option);
4801             if (IsGeometry(argv[i]) == MagickFalse)
4802               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4803             break;
4804           }
4805         if (LocaleCompare("intent",option+1) == 0)
4806           {
4807             ssize_t
4808               intent;
4809
4810             if (*option == '+')
4811               break;
4812             i++;
4813             if (i == (ssize_t) (argc-1))
4814               ThrowMogrifyException(OptionError,"MissingArgument",option);
4815             intent=ParseCommandOption(MagickIntentOptions,MagickFalse,argv[i]);
4816             if (intent < 0)
4817               ThrowMogrifyException(OptionError,"UnrecognizedIntentType",
4818                 argv[i]);
4819             break;
4820           }
4821         if (LocaleCompare("interlace",option+1) == 0)
4822           {
4823             ssize_t
4824               interlace;
4825
4826             if (*option == '+')
4827               break;
4828             i++;
4829             if (i == (ssize_t) argc)
4830               ThrowMogrifyException(OptionError,"MissingArgument",option);
4831             interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
4832               argv[i]);
4833             if (interlace < 0)
4834               ThrowMogrifyException(OptionError,"UnrecognizedInterlaceType",
4835                 argv[i]);
4836             break;
4837           }
4838         if (LocaleCompare("interline-spacing",option+1) == 0)
4839           {
4840             if (*option == '+')
4841               break;
4842             i++;
4843             if (i == (ssize_t) (argc-1))
4844               ThrowMogrifyException(OptionError,"MissingArgument",option);
4845             if (IsGeometry(argv[i]) == MagickFalse)
4846               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4847             break;
4848           }
4849         if (LocaleCompare("interpolate",option+1) == 0)
4850           {
4851             ssize_t
4852               interpolate;
4853
4854             if (*option == '+')
4855               break;
4856             i++;
4857             if (i == (ssize_t) argc)
4858               ThrowMogrifyException(OptionError,"MissingArgument",option);
4859             interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
4860               argv[i]);
4861             if (interpolate < 0)
4862               ThrowMogrifyException(OptionError,"UnrecognizedInterpolateMethod",
4863                 argv[i]);
4864             break;
4865           }
4866         if (LocaleCompare("interword-spacing",option+1) == 0)
4867           {
4868             if (*option == '+')
4869               break;
4870             i++;
4871             if (i == (ssize_t) (argc-1))
4872               ThrowMogrifyException(OptionError,"MissingArgument",option);
4873             if (IsGeometry(argv[i]) == MagickFalse)
4874               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4875             break;
4876           }
4877         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4878       }
4879       case 'k':
4880       {
4881         if (LocaleCompare("kerning",option+1) == 0)
4882           {
4883             if (*option == '+')
4884               break;
4885             i++;
4886             if (i == (ssize_t) (argc-1))
4887               ThrowMogrifyException(OptionError,"MissingArgument",option);
4888             if (IsGeometry(argv[i]) == MagickFalse)
4889               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4890             break;
4891           }
4892         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
4893       }
4894       case 'l':
4895       {
4896         if (LocaleCompare("label",option+1) == 0)
4897           {
4898             if (*option == '+')
4899               break;
4900             i++;
4901             if (i == (ssize_t) argc)
4902               ThrowMogrifyException(OptionError,"MissingArgument",option);
4903             break;
4904           }
4905         if (LocaleCompare("lat",option+1) == 0)
4906           {
4907             if (*option == '+')
4908               break;
4909             i++;
4910             if (i == (ssize_t) argc)
4911               ThrowMogrifyException(OptionError,"MissingArgument",option);
4912             if (IsGeometry(argv[i]) == MagickFalse)
4913               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4914           }
4915         if (LocaleCompare("layers",option+1) == 0)
4916           {
4917             ssize_t
4918               type;
4919
4920             if (*option == '+')
4921               break;
4922             i++;
4923             if (i == (ssize_t) (argc-1))
4924               ThrowMogrifyException(OptionError,"MissingArgument",option);
4925             type=ParseCommandOption(MagickLayerOptions,MagickFalse,argv[i]);
4926             if (type < 0)
4927               ThrowMogrifyException(OptionError,"UnrecognizedLayerMethod",
4928                 argv[i]);
4929             break;
4930           }
4931         if (LocaleCompare("level",option+1) == 0)
4932           {
4933             i++;
4934             if (i == (ssize_t) argc)
4935               ThrowMogrifyException(OptionError,"MissingArgument",option);
4936             if (IsGeometry(argv[i]) == MagickFalse)
4937               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4938             break;
4939           }
4940         if (LocaleCompare("level-colors",option+1) == 0)
4941           {
4942             i++;
4943             if (i == (ssize_t) argc)
4944               ThrowMogrifyException(OptionError,"MissingArgument",option);
4945             break;
4946           }
4947         if (LocaleCompare("linewidth",option+1) == 0)
4948           {
4949             if (*option == '+')
4950               break;
4951             i++;
4952             if (i == (ssize_t) argc)
4953               ThrowMogrifyException(OptionError,"MissingArgument",option);
4954             if (IsGeometry(argv[i]) == MagickFalse)
4955               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4956             break;
4957           }
4958         if (LocaleCompare("limit",option+1) == 0)
4959           {
4960             char
4961               *p;
4962
4963             double
4964               value;
4965
4966             ssize_t
4967               resource;
4968
4969             if (*option == '+')
4970               break;
4971             i++;
4972             if (i == (ssize_t) argc)
4973               ThrowMogrifyException(OptionError,"MissingArgument",option);
4974             resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
4975               argv[i]);
4976             if (resource < 0)
4977               ThrowMogrifyException(OptionError,"UnrecognizedResourceType",
4978                 argv[i]);
4979             i++;
4980             if (i == (ssize_t) argc)
4981               ThrowMogrifyException(OptionError,"MissingArgument",option);
4982             value=StringToDouble(argv[i],&p);
4983             (void) value;
4984             if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
4985               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4986             break;
4987           }
4988         if (LocaleCompare("liquid-rescale",option+1) == 0)
4989           {
4990             i++;
4991             if (i == (ssize_t) argc)
4992               ThrowMogrifyException(OptionError,"MissingArgument",option);
4993             if (IsGeometry(argv[i]) == MagickFalse)
4994               ThrowMogrifyInvalidArgumentException(option,argv[i]);
4995             break;
4996           }
4997         if (LocaleCompare("list",option+1) == 0)
4998           {
4999             ssize_t
5000               list;
5001
5002             if (*option == '+')
5003               break;
5004             i++;
5005             if (i == (ssize_t) argc)
5006               ThrowMogrifyException(OptionError,"MissingArgument",option);
5007             list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
5008             if (list < 0)
5009               ThrowMogrifyException(OptionError,"UnrecognizedListType",argv[i]);
5010             status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
5011               argv+j,exception);
5012             return(status != 0 ? MagickFalse : MagickTrue);
5013           }
5014         if (LocaleCompare("log",option+1) == 0)
5015           {
5016             if (*option == '+')
5017               break;
5018             i++;
5019             if ((i == (ssize_t) argc) ||
5020                 (strchr(argv[i],'%') == (char *) NULL))
5021               ThrowMogrifyException(OptionError,"MissingArgument",option);
5022             break;
5023           }
5024         if (LocaleCompare("loop",option+1) == 0)
5025           {
5026             if (*option == '+')
5027               break;
5028             i++;
5029             if (i == (ssize_t) argc)
5030               ThrowMogrifyException(OptionError,"MissingArgument",option);
5031             if (IsGeometry(argv[i]) == MagickFalse)
5032               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5033             break;
5034           }
5035         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5036       }
5037       case 'm':
5038       {
5039         if (LocaleCompare("map",option+1) == 0)
5040           {
5041             global_colormap=(*option == '+') ? MagickTrue : MagickFalse;
5042             if (*option == '+')
5043               break;
5044             i++;
5045             if (i == (ssize_t) argc)
5046               ThrowMogrifyException(OptionError,"MissingArgument",option);
5047             break;
5048           }
5049         if (LocaleCompare("mask",option+1) == 0)
5050           {
5051             if (*option == '+')
5052               break;
5053             i++;
5054             if (i == (ssize_t) argc)
5055               ThrowMogrifyException(OptionError,"MissingArgument",option);
5056             break;
5057           }
5058         if (LocaleCompare("matte",option+1) == 0)
5059           break;
5060         if (LocaleCompare("mattecolor",option+1) == 0)
5061           {
5062             if (*option == '+')
5063               break;
5064             i++;
5065             if (i == (ssize_t) argc)
5066               ThrowMogrifyException(OptionError,"MissingArgument",option);
5067             break;
5068           }
5069         if (LocaleCompare("maximum",option+1) == 0)
5070           break;
5071         if (LocaleCompare("minimum",option+1) == 0)
5072           break;
5073         if (LocaleCompare("modulate",option+1) == 0)
5074           {
5075             if (*option == '+')
5076               break;
5077             i++;
5078             if (i == (ssize_t) argc)
5079               ThrowMogrifyException(OptionError,"MissingArgument",option);
5080             if (IsGeometry(argv[i]) == MagickFalse)
5081               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5082             break;
5083           }
5084         if (LocaleCompare("median",option+1) == 0)
5085           {
5086             if (*option == '+')
5087               break;
5088             i++;
5089             if (i == (ssize_t) argc)
5090               ThrowMogrifyException(OptionError,"MissingArgument",option);
5091             if (IsGeometry(argv[i]) == MagickFalse)
5092               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5093             break;
5094           }
5095         if (LocaleCompare("mode",option+1) == 0)
5096           {
5097             if (*option == '+')
5098               break;
5099             i++;
5100             if (i == (ssize_t) argc)
5101               ThrowMogrifyException(OptionError,"MissingArgument",option);
5102             if (IsGeometry(argv[i]) == MagickFalse)
5103               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5104             break;
5105           }
5106         if (LocaleCompare("monitor",option+1) == 0)
5107           break;
5108         if (LocaleCompare("monochrome",option+1) == 0)
5109           break;
5110         if (LocaleCompare("morph",option+1) == 0)
5111           {
5112             if (*option == '+')
5113               break;
5114             i++;
5115             if (i == (ssize_t) (argc-1))
5116               ThrowMogrifyException(OptionError,"MissingArgument",option);
5117             if (IsGeometry(argv[i]) == MagickFalse)
5118               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5119             break;
5120           }
5121         if (LocaleCompare("morphology",option+1) == 0)
5122           {
5123             char
5124               token[MaxTextExtent];
5125
5126             KernelInfo
5127               *kernel_info;
5128
5129             ssize_t
5130               op;
5131
5132             i++;
5133             if (i == (ssize_t) argc)
5134               ThrowMogrifyException(OptionError,"MissingArgument",option);
5135             GetMagickToken(argv[i],NULL,token);
5136             op=ParseCommandOption(MagickMorphologyOptions,MagickFalse,token);
5137             if (op < 0)
5138               ThrowMogrifyException(OptionError,"UnrecognizedMorphologyMethod",
5139                 token);
5140             i++;
5141             if (i == (ssize_t) (argc-1))
5142               ThrowMogrifyException(OptionError,"MissingArgument",option);
5143             kernel_info=AcquireKernelInfo(argv[i]);
5144             if (kernel_info == (KernelInfo *) NULL)
5145               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5146             kernel_info=DestroyKernelInfo(kernel_info);
5147             break;
5148           }
5149         if (LocaleCompare("mosaic",option+1) == 0)
5150           break;
5151         if (LocaleCompare("motion-blur",option+1) == 0)
5152           {
5153             if (*option == '+')
5154               break;
5155             i++;
5156             if (i == (ssize_t) argc)
5157               ThrowMogrifyException(OptionError,"MissingArgument",option);
5158             if (IsGeometry(argv[i]) == MagickFalse)
5159               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5160             break;
5161           }
5162         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5163       }
5164       case 'n':
5165       {
5166         if (LocaleCompare("negate",option+1) == 0)
5167           break;
5168         if (LocaleCompare("noise",option+1) == 0)
5169           {
5170             i++;
5171             if (i == (ssize_t) argc)
5172               ThrowMogrifyException(OptionError,"MissingArgument",option);
5173             if (*option == '+')
5174               {
5175                 ssize_t
5176                   noise;
5177
5178                 noise=ParseCommandOption(MagickNoiseOptions,MagickFalse,argv[i]);
5179                 if (noise < 0)
5180                   ThrowMogrifyException(OptionError,"UnrecognizedNoiseType",
5181                     argv[i]);
5182                 break;
5183               }
5184             if (IsGeometry(argv[i]) == MagickFalse)
5185               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5186             break;
5187           }
5188         if (LocaleCompare("noop",option+1) == 0)
5189           break;
5190         if (LocaleCompare("normalize",option+1) == 0)
5191           break;
5192         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5193       }
5194       case 'o':
5195       {
5196         if (LocaleCompare("opaque",option+1) == 0)
5197           {
5198             i++;
5199             if (i == (ssize_t) argc)
5200               ThrowMogrifyException(OptionError,"MissingArgument",option);
5201             break;
5202           }
5203         if (LocaleCompare("ordered-dither",option+1) == 0)
5204           {
5205             if (*option == '+')
5206               break;
5207             i++;
5208             if (i == (ssize_t) argc)
5209               ThrowMogrifyException(OptionError,"MissingArgument",option);
5210             break;
5211           }
5212         if (LocaleCompare("orient",option+1) == 0)
5213           {
5214             ssize_t
5215               orientation;
5216
5217             orientation=UndefinedOrientation;
5218             if (*option == '+')
5219               break;
5220             i++;
5221             if (i == (ssize_t) (argc-1))
5222               ThrowMogrifyException(OptionError,"MissingArgument",option);
5223             orientation=ParseCommandOption(MagickOrientationOptions,MagickFalse,
5224               argv[i]);
5225             if (orientation < 0)
5226               ThrowMogrifyException(OptionError,"UnrecognizedImageOrientation",
5227                 argv[i]);
5228             break;
5229           }
5230         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5231       }
5232       case 'p':
5233       {
5234         if (LocaleCompare("page",option+1) == 0)
5235           {
5236             if (*option == '+')
5237               break;
5238             i++;
5239             if (i == (ssize_t) argc)
5240               ThrowMogrifyException(OptionError,"MissingArgument",option);
5241             break;
5242           }
5243         if (LocaleCompare("paint",option+1) == 0)
5244           {
5245             if (*option == '+')
5246               break;
5247             i++;
5248             if (i == (ssize_t) argc)
5249               ThrowMogrifyException(OptionError,"MissingArgument",option);
5250             if (IsGeometry(argv[i]) == MagickFalse)
5251               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5252             break;
5253           }
5254         if (LocaleCompare("path",option+1) == 0)
5255           {
5256             (void) CloneString(&path,(char *) NULL);
5257             if (*option == '+')
5258               break;
5259             i++;
5260             if (i == (ssize_t) argc)
5261               ThrowMogrifyException(OptionError,"MissingArgument",option);
5262             (void) CloneString(&path,argv[i]);
5263             break;
5264           }
5265         if (LocaleCompare("pointsize",option+1) == 0)
5266           {
5267             if (*option == '+')
5268               break;
5269             i++;
5270             if (i == (ssize_t) argc)
5271               ThrowMogrifyException(OptionError,"MissingArgument",option);
5272             if (IsGeometry(argv[i]) == MagickFalse)
5273               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5274             break;
5275           }
5276         if (LocaleCompare("polaroid",option+1) == 0)
5277           {
5278             if (*option == '+')
5279               break;
5280             i++;
5281             if (i == (ssize_t) argc)
5282               ThrowMogrifyException(OptionError,"MissingArgument",option);
5283             if (IsGeometry(argv[i]) == MagickFalse)
5284               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5285             break;
5286           }
5287         if (LocaleCompare("posterize",option+1) == 0)
5288           {
5289             if (*option == '+')
5290               break;
5291             i++;
5292             if (i == (ssize_t) argc)
5293               ThrowMogrifyException(OptionError,"MissingArgument",option);
5294             if (IsGeometry(argv[i]) == MagickFalse)
5295               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5296             break;
5297           }
5298         if (LocaleCompare("precision",option+1) == 0)
5299           {
5300             if (*option == '+')
5301               break;
5302             i++;
5303             if (i == (ssize_t) argc)
5304               ThrowMogrifyException(OptionError,"MissingArgument",option);
5305             if (IsGeometry(argv[i]) == MagickFalse)
5306               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5307             break;
5308           }
5309         if (LocaleCompare("print",option+1) == 0)
5310           {
5311             if (*option == '+')
5312               break;
5313             i++;
5314             if (i == (ssize_t) argc)
5315               ThrowMogrifyException(OptionError,"MissingArgument",option);
5316             break;
5317           }
5318         if (LocaleCompare("process",option+1) == 0)
5319           {
5320             if (*option == '+')
5321               break;
5322             i++;
5323             if (i == (ssize_t) (argc-1))
5324               ThrowMogrifyException(OptionError,"MissingArgument",option);
5325             break;
5326           }
5327         if (LocaleCompare("profile",option+1) == 0)
5328           {
5329             i++;
5330             if (i == (ssize_t) argc)
5331               ThrowMogrifyException(OptionError,"MissingArgument",option);
5332             break;
5333           }
5334         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5335       }
5336       case 'q':
5337       {
5338         if (LocaleCompare("quality",option+1) == 0)
5339           {
5340             if (*option == '+')
5341               break;
5342             i++;
5343             if (i == (ssize_t) argc)
5344               ThrowMogrifyException(OptionError,"MissingArgument",option);
5345             if (IsGeometry(argv[i]) == MagickFalse)
5346               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5347             break;
5348           }
5349         if (LocaleCompare("quantize",option+1) == 0)
5350           {
5351             ssize_t
5352               colorspace;
5353
5354             if (*option == '+')
5355               break;
5356             i++;
5357             if (i == (ssize_t) (argc-1))
5358               ThrowMogrifyException(OptionError,"MissingArgument",option);
5359             colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
5360               argv[i]);
5361             if (colorspace < 0)
5362               ThrowMogrifyException(OptionError,"UnrecognizedColorspace",
5363                 argv[i]);
5364             break;
5365           }
5366         if (LocaleCompare("quiet",option+1) == 0)
5367           break;
5368         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5369       }
5370       case 'r':
5371       {
5372         if (LocaleCompare("radial-blur",option+1) == 0)
5373           {
5374             i++;
5375             if (i == (ssize_t) argc)
5376               ThrowMogrifyException(OptionError,"MissingArgument",option);
5377             if (IsGeometry(argv[i]) == MagickFalse)
5378               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5379             break;
5380           }
5381         if (LocaleCompare("raise",option+1) == 0)
5382           {
5383             i++;
5384             if (i == (ssize_t) argc)
5385               ThrowMogrifyException(OptionError,"MissingArgument",option);
5386             if (IsGeometry(argv[i]) == MagickFalse)
5387               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5388             break;
5389           }
5390         if (LocaleCompare("random-threshold",option+1) == 0)
5391           {
5392             if (*option == '+')
5393               break;
5394             i++;
5395             if (i == (ssize_t) argc)
5396               ThrowMogrifyException(OptionError,"MissingArgument",option);
5397             if (IsGeometry(argv[i]) == MagickFalse)
5398               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5399             break;
5400           }
5401         if (LocaleCompare("recolor",option+1) == 0)
5402           {
5403             if (*option == '+')
5404               break;
5405             i++;
5406             if (i == (ssize_t) (argc-1))
5407               ThrowMogrifyException(OptionError,"MissingArgument",option);
5408             if (IsGeometry(argv[i]) == MagickFalse)
5409               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5410             break;
5411           }
5412         if (LocaleCompare("red-primary",option+1) == 0)
5413           {
5414             if (*option == '+')
5415               break;
5416             i++;
5417             if (i == (ssize_t) argc)
5418               ThrowMogrifyException(OptionError,"MissingArgument",option);
5419             if (IsGeometry(argv[i]) == MagickFalse)
5420               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5421           }
5422         if (LocaleCompare("regard-warnings",option+1) == 0)
5423           break;
5424         if (LocaleCompare("region",option+1) == 0)
5425           {
5426             if (*option == '+')
5427               break;
5428             i++;
5429             if (i == (ssize_t) argc)
5430               ThrowMogrifyException(OptionError,"MissingArgument",option);
5431             if (IsGeometry(argv[i]) == MagickFalse)
5432               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5433             break;
5434           }
5435         if (LocaleCompare("remap",option+1) == 0)
5436           {
5437             if (*option == '+')
5438               break;
5439             i++;
5440             if (i == (ssize_t) (argc-1))
5441               ThrowMogrifyException(OptionError,"MissingArgument",option);
5442             break;
5443           }
5444         if (LocaleCompare("render",option+1) == 0)
5445           break;
5446         if (LocaleCompare("repage",option+1) == 0)
5447           {
5448             if (*option == '+')
5449               break;
5450             i++;
5451             if (i == (ssize_t) argc)
5452               ThrowMogrifyException(OptionError,"MissingArgument",option);
5453             if (IsGeometry(argv[i]) == MagickFalse)
5454               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5455             break;
5456           }
5457         if (LocaleCompare("resample",option+1) == 0)
5458           {
5459             if (*option == '+')
5460               break;
5461             i++;
5462             if (i == (ssize_t) argc)
5463               ThrowMogrifyException(OptionError,"MissingArgument",option);
5464             if (IsGeometry(argv[i]) == MagickFalse)
5465               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5466             break;
5467           }
5468         if (LocaleCompare("resize",option+1) == 0)
5469           {
5470             if (*option == '+')
5471               break;
5472             i++;
5473             if (i == (ssize_t) argc)
5474               ThrowMogrifyException(OptionError,"MissingArgument",option);
5475             if (IsGeometry(argv[i]) == MagickFalse)
5476               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5477             break;
5478           }
5479         if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
5480           {
5481             respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
5482             break;
5483           }
5484         if (LocaleCompare("reverse",option+1) == 0)
5485           break;
5486         if (LocaleCompare("roll",option+1) == 0)
5487           {
5488             if (*option == '+')
5489               break;
5490             i++;
5491             if (i == (ssize_t) argc)
5492               ThrowMogrifyException(OptionError,"MissingArgument",option);
5493             if (IsGeometry(argv[i]) == MagickFalse)
5494               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5495             break;
5496           }
5497         if (LocaleCompare("rotate",option+1) == 0)
5498           {
5499             i++;
5500             if (i == (ssize_t) argc)
5501               ThrowMogrifyException(OptionError,"MissingArgument",option);
5502             if (IsGeometry(argv[i]) == MagickFalse)
5503               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5504             break;
5505           }
5506         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5507       }
5508       case 's':
5509       {
5510         if (LocaleCompare("sample",option+1) == 0)
5511           {
5512             if (*option == '+')
5513               break;
5514             i++;
5515             if (i == (ssize_t) argc)
5516               ThrowMogrifyException(OptionError,"MissingArgument",option);
5517             if (IsGeometry(argv[i]) == MagickFalse)
5518               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5519             break;
5520           }
5521         if (LocaleCompare("sampling-factor",option+1) == 0)
5522           {
5523             if (*option == '+')
5524               break;
5525             i++;
5526             if (i == (ssize_t) argc)
5527               ThrowMogrifyException(OptionError,"MissingArgument",option);
5528             if (IsGeometry(argv[i]) == MagickFalse)
5529               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5530             break;
5531           }
5532         if (LocaleCompare("scale",option+1) == 0)
5533           {
5534             if (*option == '+')
5535               break;
5536             i++;
5537             if (i == (ssize_t) argc)
5538               ThrowMogrifyException(OptionError,"MissingArgument",option);
5539             if (IsGeometry(argv[i]) == MagickFalse)
5540               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5541             break;
5542           }
5543         if (LocaleCompare("scene",option+1) == 0)
5544           {
5545             if (*option == '+')
5546               break;
5547             i++;
5548             if (i == (ssize_t) argc)
5549               ThrowMogrifyException(OptionError,"MissingArgument",option);
5550             if (IsGeometry(argv[i]) == MagickFalse)
5551               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5552             break;
5553           }
5554         if (LocaleCompare("seed",option+1) == 0)
5555           {
5556             if (*option == '+')
5557               break;
5558             i++;
5559             if (i == (ssize_t) argc)
5560               ThrowMogrifyException(OptionError,"MissingArgument",option);
5561             if (IsGeometry(argv[i]) == MagickFalse)
5562               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5563             break;
5564           }
5565         if (LocaleCompare("segment",option+1) == 0)
5566           {
5567             if (*option == '+')
5568               break;
5569             i++;
5570             if (i == (ssize_t) argc)
5571               ThrowMogrifyException(OptionError,"MissingArgument",option);
5572             if (IsGeometry(argv[i]) == MagickFalse)
5573               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5574             break;
5575           }
5576         if (LocaleCompare("selective-blur",option+1) == 0)
5577           {
5578             i++;
5579             if (i == (ssize_t) argc)
5580               ThrowMogrifyException(OptionError,"MissingArgument",option);
5581             if (IsGeometry(argv[i]) == MagickFalse)
5582               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5583             break;
5584           }
5585         if (LocaleCompare("separate",option+1) == 0)
5586           break;
5587         if (LocaleCompare("sepia-tone",option+1) == 0)
5588           {
5589             if (*option == '+')
5590               break;
5591             i++;
5592             if (i == (ssize_t) argc)
5593               ThrowMogrifyException(OptionError,"MissingArgument",option);
5594             if (IsGeometry(argv[i]) == MagickFalse)
5595               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5596             break;
5597           }
5598         if (LocaleCompare("set",option+1) == 0)
5599           {
5600             i++;
5601             if (i == (ssize_t) argc)
5602               ThrowMogrifyException(OptionError,"MissingArgument",option);
5603             if (*option == '+')
5604               break;
5605             i++;
5606             if (i == (ssize_t) argc)
5607               ThrowMogrifyException(OptionError,"MissingArgument",option);
5608             break;
5609           }
5610         if (LocaleCompare("shade",option+1) == 0)
5611           {
5612             i++;
5613             if (i == (ssize_t) argc)
5614               ThrowMogrifyException(OptionError,"MissingArgument",option);
5615             if (IsGeometry(argv[i]) == MagickFalse)
5616               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5617             break;
5618           }
5619         if (LocaleCompare("shadow",option+1) == 0)
5620           {
5621             if (*option == '+')
5622               break;
5623             i++;
5624             if (i == (ssize_t) argc)
5625               ThrowMogrifyException(OptionError,"MissingArgument",option);
5626             if (IsGeometry(argv[i]) == MagickFalse)
5627               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5628             break;
5629           }
5630         if (LocaleCompare("sharpen",option+1) == 0)
5631           {
5632             i++;
5633             if (i == (ssize_t) argc)
5634               ThrowMogrifyException(OptionError,"MissingArgument",option);
5635             if (IsGeometry(argv[i]) == MagickFalse)
5636               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5637             break;
5638           }
5639         if (LocaleCompare("shave",option+1) == 0)
5640           {
5641             if (*option == '+')
5642               break;
5643             i++;
5644             if (i == (ssize_t) argc)
5645               ThrowMogrifyException(OptionError,"MissingArgument",option);
5646             if (IsGeometry(argv[i]) == MagickFalse)
5647               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5648             break;
5649           }
5650         if (LocaleCompare("shear",option+1) == 0)
5651           {
5652             i++;
5653             if (i == (ssize_t) argc)
5654               ThrowMogrifyException(OptionError,"MissingArgument",option);
5655             if (IsGeometry(argv[i]) == MagickFalse)
5656               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5657             break;
5658           }
5659         if (LocaleCompare("sigmoidal-contrast",option+1) == 0)
5660           {
5661             i++;
5662             if (i == (ssize_t) (argc-1))
5663               ThrowMogrifyException(OptionError,"MissingArgument",option);
5664             if (IsGeometry(argv[i]) == MagickFalse)
5665               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5666             break;
5667           }
5668         if (LocaleCompare("size",option+1) == 0)
5669           {
5670             if (*option == '+')
5671               break;
5672             i++;
5673             if (i == (ssize_t) argc)
5674               ThrowMogrifyException(OptionError,"MissingArgument",option);
5675             if (IsGeometry(argv[i]) == MagickFalse)
5676               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5677             break;
5678           }
5679         if (LocaleCompare("sketch",option+1) == 0)
5680           {
5681             if (*option == '+')
5682               break;
5683             i++;
5684             if (i == (ssize_t) argc)
5685               ThrowMogrifyException(OptionError,"MissingArgument",option);
5686             if (IsGeometry(argv[i]) == MagickFalse)
5687               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5688             break;
5689           }
5690         if (LocaleCompare("smush",option+1) == 0)
5691           {
5692             i++;
5693             if (i == (ssize_t) argc)
5694               ThrowMogrifyException(OptionError,"MissingArgument",option);
5695             if (IsGeometry(argv[i]) == MagickFalse)
5696               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5697             i++;
5698             break;
5699           }
5700         if (LocaleCompare("solarize",option+1) == 0)
5701           {
5702             if (*option == '+')
5703               break;
5704             i++;
5705             if (i == (ssize_t) argc)
5706               ThrowMogrifyException(OptionError,"MissingArgument",option);
5707             if (IsGeometry(argv[i]) == MagickFalse)
5708               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5709             break;
5710           }
5711         if (LocaleCompare("sparse-color",option+1) == 0)
5712           {
5713             ssize_t
5714               op;
5715
5716             i++;
5717             if (i == (ssize_t) argc)
5718               ThrowMogrifyException(OptionError,"MissingArgument",option);
5719             op=ParseCommandOption(MagickSparseColorOptions,MagickFalse,argv[i]);
5720             if (op < 0)
5721               ThrowMogrifyException(OptionError,"UnrecognizedSparseColorMethod",
5722                 argv[i]);
5723             i++;
5724             if (i == (ssize_t) (argc-1))
5725               ThrowMogrifyException(OptionError,"MissingArgument",option);
5726             break;
5727           }
5728         if (LocaleCompare("spread",option+1) == 0)
5729           {
5730             if (*option == '+')
5731               break;
5732             i++;
5733             if (i == (ssize_t) argc)
5734               ThrowMogrifyException(OptionError,"MissingArgument",option);
5735             if (IsGeometry(argv[i]) == MagickFalse)
5736               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5737             break;
5738           }
5739         if (LocaleCompare("statistic",option+1) == 0)
5740           {
5741             ssize_t
5742               op;
5743
5744             if (*option == '+')
5745               break;
5746             i++;
5747             if (i == (ssize_t) argc)
5748               ThrowMogrifyException(OptionError,"MissingArgument",option);
5749             op=ParseCommandOption(MagickStatisticOptions,MagickFalse,argv[i]);
5750             if (op < 0)
5751               ThrowMogrifyException(OptionError,"UnrecognizedStatisticType",
5752                 argv[i]);
5753             i++;
5754             if (i == (ssize_t) (argc-1))
5755               ThrowMogrifyException(OptionError,"MissingArgument",option);
5756             if (IsGeometry(argv[i]) == MagickFalse)
5757               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5758             break;
5759           }
5760         if (LocaleCompare("stretch",option+1) == 0)
5761           {
5762             ssize_t
5763               stretch;
5764
5765             if (*option == '+')
5766               break;
5767             i++;
5768             if (i == (ssize_t) (argc-1))
5769               ThrowMogrifyException(OptionError,"MissingArgument",option);
5770             stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,argv[i]);
5771             if (stretch < 0)
5772               ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5773                 argv[i]);
5774             break;
5775           }
5776         if (LocaleCompare("strip",option+1) == 0)
5777           break;
5778         if (LocaleCompare("stroke",option+1) == 0)
5779           {
5780             if (*option == '+')
5781               break;
5782             i++;
5783             if (i == (ssize_t) argc)
5784               ThrowMogrifyException(OptionError,"MissingArgument",option);
5785             break;
5786           }
5787         if (LocaleCompare("strokewidth",option+1) == 0)
5788           {
5789             if (*option == '+')
5790               break;
5791             i++;
5792             if (i == (ssize_t) argc)
5793               ThrowMogrifyException(OptionError,"MissingArgument",option);
5794             if (IsGeometry(argv[i]) == MagickFalse)
5795               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5796             break;
5797           }
5798         if (LocaleCompare("style",option+1) == 0)
5799           {
5800             ssize_t
5801               style;
5802
5803             if (*option == '+')
5804               break;
5805             i++;
5806             if (i == (ssize_t) (argc-1))
5807               ThrowMogrifyException(OptionError,"MissingArgument",option);
5808             style=ParseCommandOption(MagickStyleOptions,MagickFalse,argv[i]);
5809             if (style < 0)
5810               ThrowMogrifyException(OptionError,"UnrecognizedStyleType",
5811                 argv[i]);
5812             break;
5813           }
5814         if (LocaleCompare("swap",option+1) == 0)
5815           {
5816             if (*option == '+')
5817               break;
5818             i++;
5819             if (i == (ssize_t) (argc-1))
5820               ThrowMogrifyException(OptionError,"MissingArgument",option);
5821             if (IsGeometry(argv[i]) == MagickFalse)
5822               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5823             break;
5824           }
5825         if (LocaleCompare("swirl",option+1) == 0)
5826           {
5827             if (*option == '+')
5828               break;
5829             i++;
5830             if (i == (ssize_t) argc)
5831               ThrowMogrifyException(OptionError,"MissingArgument",option);
5832             if (IsGeometry(argv[i]) == MagickFalse)
5833               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5834             break;
5835           }
5836         if (LocaleCompare("synchronize",option+1) == 0)
5837           break;
5838         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5839       }
5840       case 't':
5841       {
5842         if (LocaleCompare("taint",option+1) == 0)
5843           break;
5844         if (LocaleCompare("texture",option+1) == 0)
5845           {
5846             if (*option == '+')
5847               break;
5848             i++;
5849             if (i == (ssize_t) argc)
5850               ThrowMogrifyException(OptionError,"MissingArgument",option);
5851             break;
5852           }
5853         if (LocaleCompare("tile",option+1) == 0)
5854           {
5855             if (*option == '+')
5856               break;
5857             i++;
5858             if (i == (ssize_t) (argc-1))
5859               ThrowMogrifyException(OptionError,"MissingArgument",option);
5860             break;
5861           }
5862         if (LocaleCompare("tile-offset",option+1) == 0)
5863           {
5864             if (*option == '+')
5865               break;
5866             i++;
5867             if (i == (ssize_t) argc)
5868               ThrowMogrifyException(OptionError,"MissingArgument",option);
5869             if (IsGeometry(argv[i]) == MagickFalse)
5870               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5871             break;
5872           }
5873         if (LocaleCompare("tint",option+1) == 0)
5874           {
5875             if (*option == '+')
5876               break;
5877             i++;
5878             if (i == (ssize_t) (argc-1))
5879               ThrowMogrifyException(OptionError,"MissingArgument",option);
5880             if (IsGeometry(argv[i]) == MagickFalse)
5881               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5882             break;
5883           }
5884         if (LocaleCompare("transform",option+1) == 0)
5885           break;
5886         if (LocaleCompare("transpose",option+1) == 0)
5887           break;
5888         if (LocaleCompare("transverse",option+1) == 0)
5889           break;
5890         if (LocaleCompare("threshold",option+1) == 0)
5891           {
5892             if (*option == '+')
5893               break;
5894             i++;
5895             if (i == (ssize_t) argc)
5896               ThrowMogrifyException(OptionError,"MissingArgument",option);
5897             if (IsGeometry(argv[i]) == MagickFalse)
5898               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5899             break;
5900           }
5901         if (LocaleCompare("thumbnail",option+1) == 0)
5902           {
5903             if (*option == '+')
5904               break;
5905             i++;
5906             if (i == (ssize_t) argc)
5907               ThrowMogrifyException(OptionError,"MissingArgument",option);
5908             if (IsGeometry(argv[i]) == MagickFalse)
5909               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5910             break;
5911           }
5912         if (LocaleCompare("transparent",option+1) == 0)
5913           {
5914             i++;
5915             if (i == (ssize_t) argc)
5916               ThrowMogrifyException(OptionError,"MissingArgument",option);
5917             break;
5918           }
5919         if (LocaleCompare("transparent-color",option+1) == 0)
5920           {
5921             if (*option == '+')
5922               break;
5923             i++;
5924             if (i == (ssize_t) (argc-1))
5925               ThrowMogrifyException(OptionError,"MissingArgument",option);
5926             break;
5927           }
5928         if (LocaleCompare("treedepth",option+1) == 0)
5929           {
5930             if (*option == '+')
5931               break;
5932             i++;
5933             if (i == (ssize_t) argc)
5934               ThrowMogrifyException(OptionError,"MissingArgument",option);
5935             if (IsGeometry(argv[i]) == MagickFalse)
5936               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5937             break;
5938           }
5939         if (LocaleCompare("trim",option+1) == 0)
5940           break;
5941         if (LocaleCompare("type",option+1) == 0)
5942           {
5943             ssize_t
5944               type;
5945
5946             if (*option == '+')
5947               break;
5948             i++;
5949             if (i == (ssize_t) argc)
5950               ThrowMogrifyException(OptionError,"MissingArgument",option);
5951             type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
5952             if (type < 0)
5953               ThrowMogrifyException(OptionError,"UnrecognizedImageType",
5954                 argv[i]);
5955             break;
5956           }
5957         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5958       }
5959       case 'u':
5960       {
5961         if (LocaleCompare("undercolor",option+1) == 0)
5962           {
5963             if (*option == '+')
5964               break;
5965             i++;
5966             if (i == (ssize_t) argc)
5967               ThrowMogrifyException(OptionError,"MissingArgument",option);
5968             break;
5969           }
5970         if (LocaleCompare("unique-colors",option+1) == 0)
5971           break;
5972         if (LocaleCompare("units",option+1) == 0)
5973           {
5974             ssize_t
5975               units;
5976
5977             if (*option == '+')
5978               break;
5979             i++;
5980             if (i == (ssize_t) argc)
5981               ThrowMogrifyException(OptionError,"MissingArgument",option);
5982             units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
5983               argv[i]);
5984             if (units < 0)
5985               ThrowMogrifyException(OptionError,"UnrecognizedUnitsType",
5986                 argv[i]);
5987             break;
5988           }
5989         if (LocaleCompare("unsharp",option+1) == 0)
5990           {
5991             i++;
5992             if (i == (ssize_t) argc)
5993               ThrowMogrifyException(OptionError,"MissingArgument",option);
5994             if (IsGeometry(argv[i]) == MagickFalse)
5995               ThrowMogrifyInvalidArgumentException(option,argv[i]);
5996             break;
5997           }
5998         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
5999       }
6000       case 'v':
6001       {
6002         if (LocaleCompare("verbose",option+1) == 0)
6003           {
6004             image_info->verbose=(*option == '-') ? MagickTrue : MagickFalse;
6005             break;
6006           }
6007         if ((LocaleCompare("version",option+1) == 0) ||
6008             (LocaleCompare("-version",option+1) == 0))
6009           {
6010             (void) FormatLocaleFile(stdout,"Version: %s\n",
6011               GetMagickVersion((size_t *) NULL));
6012             (void) FormatLocaleFile(stdout,"Copyright: %s\n",
6013               GetMagickCopyright());
6014             (void) FormatLocaleFile(stdout,"Features: %s\n\n",
6015               GetMagickFeatures());
6016             break;
6017           }
6018         if (LocaleCompare("view",option+1) == 0)
6019           {
6020             if (*option == '+')
6021               break;
6022             i++;
6023             if (i == (ssize_t) argc)
6024               ThrowMogrifyException(OptionError,"MissingArgument",option);
6025             break;
6026           }
6027         if (LocaleCompare("vignette",option+1) == 0)
6028           {
6029             if (*option == '+')
6030               break;
6031             i++;
6032             if (i == (ssize_t) argc)
6033               ThrowMogrifyException(OptionError,"MissingArgument",option);
6034             if (IsGeometry(argv[i]) == MagickFalse)
6035               ThrowMogrifyInvalidArgumentException(option,argv[i]);
6036             break;
6037           }
6038         if (LocaleCompare("virtual-pixel",option+1) == 0)
6039           {
6040             ssize_t
6041               method;
6042
6043             if (*option == '+')
6044               break;
6045             i++;
6046             if (i == (ssize_t) argc)
6047               ThrowMogrifyException(OptionError,"MissingArgument",option);
6048             method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
6049               argv[i]);
6050             if (method < 0)
6051               ThrowMogrifyException(OptionError,
6052                 "UnrecognizedVirtualPixelMethod",argv[i]);
6053             break;
6054           }
6055         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6056       }
6057       case 'w':
6058       {
6059         if (LocaleCompare("wave",option+1) == 0)
6060           {
6061             i++;
6062             if (i == (ssize_t) argc)
6063               ThrowMogrifyException(OptionError,"MissingArgument",option);
6064             if (IsGeometry(argv[i]) == MagickFalse)
6065               ThrowMogrifyInvalidArgumentException(option,argv[i]);
6066             break;
6067           }
6068         if (LocaleCompare("weight",option+1) == 0)
6069           {
6070             if (*option == '+')
6071               break;
6072             i++;
6073             if (i == (ssize_t) (argc-1))
6074               ThrowMogrifyException(OptionError,"MissingArgument",option);
6075             break;
6076           }
6077         if (LocaleCompare("white-point",option+1) == 0)
6078           {
6079             if (*option == '+')
6080               break;
6081             i++;
6082             if (i == (ssize_t) argc)
6083               ThrowMogrifyException(OptionError,"MissingArgument",option);
6084             if (IsGeometry(argv[i]) == MagickFalse)
6085               ThrowMogrifyInvalidArgumentException(option,argv[i]);
6086             break;
6087           }
6088         if (LocaleCompare("white-threshold",option+1) == 0)
6089           {
6090             if (*option == '+')
6091               break;
6092             i++;
6093             if (i == (ssize_t) argc)
6094               ThrowMogrifyException(OptionError,"MissingArgument",option);
6095             if (IsGeometry(argv[i]) == MagickFalse)
6096               ThrowMogrifyInvalidArgumentException(option,argv[i]);
6097             break;
6098           }
6099         if (LocaleCompare("write",option+1) == 0)
6100           {
6101             i++;
6102             if (i == (ssize_t) (argc-1))
6103               ThrowMogrifyException(OptionError,"MissingArgument",option);
6104             break;
6105           }
6106         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6107       }
6108       case '?':
6109         break;
6110       default:
6111         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
6112     }
6113     fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
6114       FireOptionFlag) == 0 ?  MagickFalse : MagickTrue;
6115     if (fire != MagickFalse)
6116       FireImageStack(MagickFalse,MagickTrue,MagickTrue);
6117   }
6118   if (k != 0)
6119     ThrowMogrifyException(OptionError,"UnbalancedParenthesis",argv[i]);
6120   if (i != (ssize_t) argc)
6121     ThrowMogrifyException(OptionError,"MissingAnImageFilename",argv[i]);
6122   DestroyMogrify();
6123   return(status != 0 ? MagickTrue : MagickFalse);
6124 }
6125 \f
6126 /*
6127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6128 %                                                                             %
6129 %                                                                             %
6130 %                                                                             %
6131 +     M o g r i f y I m a g e I n f o                                         %
6132 %                                                                             %
6133 %                                                                             %
6134 %                                                                             %
6135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6136 %
6137 %  MogrifyImageInfo() applies image processing settings to the image as
6138 %  prescribed by command line options.
6139 %
6140 %  The format of the MogrifyImageInfo method is:
6141 %
6142 %      MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,const int argc,
6143 %        const char **argv,ExceptionInfo *exception)
6144 %
6145 %  A description of each parameter follows:
6146 %
6147 %    o image_info: the image info..
6148 %
6149 %    o argc: Specifies a pointer to an integer describing the number of
6150 %      elements in the argument vector.
6151 %
6152 %    o argv: Specifies a pointer to a text array containing the command line
6153 %      arguments.
6154 %
6155 %    o exception: return any errors or warnings in this structure.
6156 %
6157 */
6158 WandExport MagickBooleanType MogrifyImageInfo(ImageInfo *image_info,
6159   const int argc,const char **argv,ExceptionInfo *exception)
6160 {
6161   const char
6162     *option;
6163
6164   GeometryInfo
6165     geometry_info;
6166
6167   ssize_t
6168     count;
6169
6170   register ssize_t
6171     i;
6172
6173   /*
6174     Initialize method variables.
6175   */
6176   assert(image_info != (ImageInfo *) NULL);
6177   assert(image_info->signature == MagickSignature);
6178   if (image_info->debug != MagickFalse)
6179     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
6180       image_info->filename);
6181   if (argc < 0)
6182     return(MagickTrue);
6183   /*
6184     Set the image settings.
6185   */
6186   for (i=0; i < (ssize_t) argc; i++)
6187   {
6188     option=argv[i];
6189     if (IsCommandOption(option) == MagickFalse)
6190       continue;
6191     count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
6192     count=MagickMax(count,0L);
6193     if ((i+count) >= (ssize_t) argc)
6194       break;
6195     switch (*(option+1))
6196     {
6197       case 'a':
6198       {
6199         if (LocaleCompare("adjoin",option+1) == 0)
6200           {
6201             image_info->adjoin=(*option == '-') ? MagickTrue : MagickFalse;
6202             break;
6203           }
6204         if (LocaleCompare("antialias",option+1) == 0)
6205           {
6206             image_info->antialias=(*option == '-') ? MagickTrue : MagickFalse;
6207             break;
6208           }
6209         if (LocaleCompare("authenticate",option+1) == 0)
6210           {
6211             if (*option == '+')
6212               (void) DeleteImageOption(image_info,option+1);
6213             else
6214               (void) SetImageOption(image_info,option+1,argv[i+1]);
6215             break;
6216           }
6217         break;
6218       }
6219       case 'b':
6220       {
6221         if (LocaleCompare("background",option+1) == 0)
6222           {
6223             if (*option == '+')
6224               {
6225                 (void) DeleteImageOption(image_info,option+1);
6226                 (void) QueryColorCompliance(MogrifyBackgroundColor,
6227                   AllCompliance,&image_info->background_color,exception);
6228                 break;
6229               }
6230             (void) SetImageOption(image_info,option+1,argv[i+1]);
6231             (void) QueryColorCompliance(argv[i+1],AllCompliance,
6232               &image_info->background_color,exception);
6233             break;
6234           }
6235         if (LocaleCompare("bias",option+1) == 0)
6236           {
6237             if (*option == '+')
6238               {
6239                 (void) SetImageOption(image_info,option+1,"0.0");
6240                 break;
6241               }
6242             (void) SetImageOption(image_info,option+1,argv[i+1]);
6243             break;
6244           }
6245         if (LocaleCompare("black-point-compensation",option+1) == 0)
6246           {
6247             if (*option == '+')
6248               {
6249                 (void) SetImageOption(image_info,option+1,"false");
6250                 break;
6251               }
6252             (void) SetImageOption(image_info,option+1,"true");
6253             break;
6254           }
6255         if (LocaleCompare("blue-primary",option+1) == 0)
6256           {
6257             if (*option == '+')
6258               {
6259                 (void) SetImageOption(image_info,option+1,"0.0");
6260                 break;
6261               }
6262             (void) SetImageOption(image_info,option+1,argv[i+1]);
6263             break;
6264           }
6265         if (LocaleCompare("bordercolor",option+1) == 0)
6266           {
6267             if (*option == '+')
6268               {
6269                 (void) DeleteImageOption(image_info,option+1);
6270                 (void) QueryColorCompliance(MogrifyBorderColor,AllCompliance,
6271                   &image_info->border_color,exception);
6272                 break;
6273               }
6274             (void) QueryColorCompliance(argv[i+1],AllCompliance,
6275               &image_info->border_color,exception);
6276             (void) SetImageOption(image_info,option+1,argv[i+1]);
6277             break;
6278           }
6279         if (LocaleCompare("box",option+1) == 0)
6280           {
6281             if (*option == '+')
6282               {
6283                 (void) SetImageOption(image_info,"undercolor","none");
6284                 break;
6285               }
6286             (void) SetImageOption(image_info,"undercolor",argv[i+1]);
6287             break;
6288           }
6289         break;
6290       }
6291       case 'c':
6292       {
6293         if (LocaleCompare("cache",option+1) == 0)
6294           {
6295             MagickSizeType
6296               limit;
6297
6298             limit=MagickResourceInfinity;
6299             if (LocaleCompare("unlimited",argv[i+1]) != 0)
6300               limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+1],
6301                 100.0);
6302             (void) SetMagickResourceLimit(MemoryResource,limit);
6303             (void) SetMagickResourceLimit(MapResource,2*limit);
6304             break;
6305           }
6306         if (LocaleCompare("caption",option+1) == 0)
6307           {
6308             if (*option == '+')
6309               {
6310                 (void) DeleteImageOption(image_info,option+1);
6311                 break;
6312               }
6313             (void) SetImageOption(image_info,option+1,argv[i+1]);
6314             break;
6315           }
6316         if (LocaleCompare("channel",option+1) == 0)
6317           {
6318             if (*option == '+')
6319               {
6320                 image_info->channel=DefaultChannels;
6321                 break;
6322               }
6323             image_info->channel=(ChannelType) ParseChannelOption(argv[i+1]);
6324             break;
6325           }
6326         if (LocaleCompare("colorspace",option+1) == 0)
6327           {
6328             if (*option == '+')
6329               {
6330                 image_info->colorspace=UndefinedColorspace;
6331                 (void) SetImageOption(image_info,option+1,"undefined");
6332                 break;
6333               }
6334             image_info->colorspace=(ColorspaceType) ParseCommandOption(
6335               MagickColorspaceOptions,MagickFalse,argv[i+1]);
6336             (void) SetImageOption(image_info,option+1,argv[i+1]);
6337             break;
6338           }
6339         if (LocaleCompare("comment",option+1) == 0)
6340           {
6341             if (*option == '+')
6342               {
6343                 (void) DeleteImageOption(image_info,option+1);
6344                 break;
6345               }
6346             (void) SetImageOption(image_info,option+1,argv[i+1]);
6347             break;
6348           }
6349         if (LocaleCompare("compose",option+1) == 0)
6350           {
6351             if (*option == '+')
6352               {
6353                 (void) SetImageOption(image_info,option+1,"undefined");
6354                 break;
6355               }
6356             (void) SetImageOption(image_info,option+1,argv[i+1]);
6357             break;
6358           }
6359         if (LocaleCompare("compress",option+1) == 0)
6360           {
6361             if (*option == '+')
6362               {
6363                 image_info->compression=UndefinedCompression;
6364                 (void) SetImageOption(image_info,option+1,"undefined");
6365                 break;
6366               }
6367             image_info->compression=(CompressionType) ParseCommandOption(
6368               MagickCompressOptions,MagickFalse,argv[i+1]);
6369             (void) SetImageOption(image_info,option+1,argv[i+1]);
6370             break;
6371           }
6372         break;
6373       }
6374       case 'd':
6375       {
6376         if (LocaleCompare("debug",option+1) == 0)
6377           {
6378             if (*option == '+')
6379               (void) SetLogEventMask("none");
6380             else
6381               (void) SetLogEventMask(argv[i+1]);
6382             image_info->debug=IsEventLogging();
6383             break;
6384           }
6385         if (LocaleCompare("define",option+1) == 0)
6386           {
6387             if (*option == '+')
6388               {
6389                 if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6390                   (void) DeleteImageRegistry(argv[i+1]+9);
6391                 else
6392                   (void) DeleteImageOption(image_info,argv[i+1]);
6393                 break;
6394               }
6395             if (LocaleNCompare(argv[i+1],"registry:",9) == 0)
6396               {
6397                 (void) DefineImageRegistry(StringRegistryType,argv[i+1]+9,
6398                   exception);
6399                 break;
6400               }
6401             (void) DefineImageOption(image_info,argv[i+1]);
6402             break;
6403           }
6404         if (LocaleCompare("delay",option+1) == 0)
6405           {
6406             if (*option == '+')
6407               {
6408                 (void) SetImageOption(image_info,option+1,"0");
6409                 break;
6410               }
6411             (void) SetImageOption(image_info,option+1,argv[i+1]);
6412             break;
6413           }
6414         if (LocaleCompare("density",option+1) == 0)
6415           {
6416             /*
6417               Set image density.
6418             */
6419             if (*option == '+')
6420               {
6421                 if (image_info->density != (char *) NULL)
6422                   image_info->density=DestroyString(image_info->density);
6423                 (void) SetImageOption(image_info,option+1,"72");
6424                 break;
6425               }
6426             (void) CloneString(&image_info->density,argv[i+1]);
6427             (void) SetImageOption(image_info,option+1,argv[i+1]);
6428             break;
6429           }
6430         if (LocaleCompare("depth",option+1) == 0)
6431           {
6432             if (*option == '+')
6433               {
6434                 image_info->depth=MAGICKCORE_QUANTUM_DEPTH;
6435                 break;
6436               }
6437             image_info->depth=StringToUnsignedLong(argv[i+1]);
6438             break;
6439           }
6440         if (LocaleCompare("direction",option+1) == 0)
6441           {
6442             if (*option == '+')
6443               {
6444                 (void) SetImageOption(image_info,option+1,"undefined");
6445                 break;
6446               }
6447             (void) SetImageOption(image_info,option+1,argv[i+1]);
6448             break;
6449           }
6450         if (LocaleCompare("display",option+1) == 0)
6451           {
6452             if (*option == '+')
6453               {
6454                 if (image_info->server_name != (char *) NULL)
6455                   image_info->server_name=DestroyString(
6456                     image_info->server_name);
6457                 break;
6458               }
6459             (void) CloneString(&image_info->server_name,argv[i+1]);
6460             break;
6461           }
6462         if (LocaleCompare("dispose",option+1) == 0)
6463           {
6464             if (*option == '+')
6465               {
6466                 (void) SetImageOption(image_info,option+1,"undefined");
6467                 break;
6468               }
6469             (void) SetImageOption(image_info,option+1,argv[i+1]);
6470             break;
6471           }
6472         if (LocaleCompare("dither",option+1) == 0)
6473           {
6474             if (*option == '+')
6475               {
6476                 image_info->dither=MagickFalse;
6477                 (void) SetImageOption(image_info,option+1,"none");
6478                 break;
6479               }
6480             (void) SetImageOption(image_info,option+1,argv[i+1]);
6481             image_info->dither=MagickTrue;
6482             break;
6483           }
6484         break;
6485       }
6486       case 'e':
6487       {
6488         if (LocaleCompare("encoding",option+1) == 0)
6489           {
6490             if (*option == '+')
6491               {
6492                 (void) SetImageOption(image_info,option+1,"undefined");
6493                 break;
6494               }
6495             (void) SetImageOption(image_info,option+1,argv[i+1]);
6496             break;
6497           }
6498         if (LocaleCompare("endian",option+1) == 0)
6499           {
6500             if (*option == '+')
6501               {
6502                 image_info->endian=UndefinedEndian;
6503                 (void) SetImageOption(image_info,option+1,"undefined");
6504                 break;
6505               }
6506             image_info->endian=(EndianType) ParseCommandOption(
6507               MagickEndianOptions,MagickFalse,argv[i+1]);
6508             (void) SetImageOption(image_info,option+1,argv[i+1]);
6509             break;
6510           }
6511         if (LocaleCompare("extract",option+1) == 0)
6512           {
6513             /*
6514               Set image extract geometry.
6515             */
6516             if (*option == '+')
6517               {
6518                 if (image_info->extract != (char *) NULL)
6519                   image_info->extract=DestroyString(image_info->extract);
6520                 break;
6521               }
6522             (void) CloneString(&image_info->extract,argv[i+1]);
6523             break;
6524           }
6525         break;
6526       }
6527       case 'f':
6528       {
6529         if (LocaleCompare("fill",option+1) == 0)
6530           {
6531             if (*option == '+')
6532               {
6533                 (void) SetImageOption(image_info,option+1,"none");
6534                 break;
6535               }
6536             (void) SetImageOption(image_info,option+1,argv[i+1]);
6537             break;
6538           }
6539         if (LocaleCompare("filter",option+1) == 0)
6540           {
6541             if (*option == '+')
6542               {
6543                 (void) SetImageOption(image_info,option+1,"undefined");
6544                 break;
6545               }
6546             (void) SetImageOption(image_info,option+1,argv[i+1]);
6547             break;
6548           }
6549         if (LocaleCompare("font",option+1) == 0)
6550           {
6551             if (*option == '+')
6552               {
6553                 if (image_info->font != (char *) NULL)
6554                   image_info->font=DestroyString(image_info->font);
6555                 break;
6556               }
6557             (void) CloneString(&image_info->font,argv[i+1]);
6558             break;
6559           }
6560         if (LocaleCompare("format",option+1) == 0)
6561           {
6562             register const char
6563               *q;
6564
6565             for (q=strchr(argv[i+1],'%'); q != (char *) NULL; q=strchr(q+1,'%'))
6566               if (strchr("Agkrz@[#",*(q+1)) != (char *) NULL)
6567                 image_info->ping=MagickFalse;
6568             (void) SetImageOption(image_info,option+1,argv[i+1]);
6569             break;
6570           }
6571         if (LocaleCompare("fuzz",option+1) == 0)
6572           {
6573             if (*option == '+')
6574               {
6575                 image_info->fuzz=0.0;
6576                 (void) SetImageOption(image_info,option+1,"0");
6577                 break;
6578               }
6579             image_info->fuzz=StringToDoubleInterval(argv[i+1],(double)
6580               QuantumRange+1.0);
6581             (void) SetImageOption(image_info,option+1,argv[i+1]);
6582             break;
6583           }
6584         break;
6585       }
6586       case 'g':
6587       {
6588         if (LocaleCompare("gravity",option+1) == 0)
6589           {
6590             if (*option == '+')
6591               {
6592                 (void) SetImageOption(image_info,option+1,"undefined");
6593                 break;
6594               }
6595             (void) SetImageOption(image_info,option+1,argv[i+1]);
6596             break;
6597           }
6598         if (LocaleCompare("green-primary",option+1) == 0)
6599           {
6600             if (*option == '+')
6601               {
6602                 (void) SetImageOption(image_info,option+1,"0.0");
6603                 break;
6604               }
6605             (void) SetImageOption(image_info,option+1,argv[i+1]);
6606             break;
6607           }
6608         break;
6609       }
6610       case 'i':
6611       {
6612         if (LocaleCompare("intent",option+1) == 0)
6613           {
6614             if (*option == '+')
6615               {
6616                 (void) SetImageOption(image_info,option+1,"undefined");
6617                 break;
6618               }
6619             (void) SetImageOption(image_info,option+1,argv[i+1]);
6620             break;
6621           }
6622         if (LocaleCompare("interlace",option+1) == 0)
6623           {
6624             if (*option == '+')
6625               {
6626                 image_info->interlace=UndefinedInterlace;
6627                 (void) SetImageOption(image_info,option+1,"undefined");
6628                 break;
6629               }
6630             image_info->interlace=(InterlaceType) ParseCommandOption(
6631               MagickInterlaceOptions,MagickFalse,argv[i+1]);
6632             (void) SetImageOption(image_info,option+1,argv[i+1]);
6633             break;
6634           }
6635         if (LocaleCompare("interline-spacing",option+1) == 0)
6636           {
6637             if (*option == '+')
6638               {
6639                 (void) SetImageOption(image_info,option+1,"undefined");
6640                 break;
6641               }
6642             (void) SetImageOption(image_info,option+1,argv[i+1]);
6643             break;
6644           }
6645         if (LocaleCompare("interpolate",option+1) == 0)
6646           {
6647             if (*option == '+')
6648               {
6649                 (void) SetImageOption(image_info,option+1,"undefined");
6650                 break;
6651               }
6652             (void) SetImageOption(image_info,option+1,argv[i+1]);
6653             break;
6654           }
6655         if (LocaleCompare("interword-spacing",option+1) == 0)
6656           {
6657             if (*option == '+')
6658               {
6659                 (void) SetImageOption(image_info,option+1,"undefined");
6660                 break;
6661               }
6662             (void) SetImageOption(image_info,option+1,argv[i+1]);
6663             break;
6664           }
6665         break;
6666       }
6667       case 'k':
6668       {
6669         if (LocaleCompare("kerning",option+1) == 0)
6670           {
6671             if (*option == '+')
6672               {
6673                 (void) SetImageOption(image_info,option+1,"undefined");
6674                 break;
6675               }
6676             (void) SetImageOption(image_info,option+1,argv[i+1]);
6677             break;
6678           }
6679         break;
6680       }
6681       case 'l':
6682       {
6683         if (LocaleCompare("label",option+1) == 0)
6684           {
6685             if (*option == '+')
6686               {
6687                 (void) DeleteImageOption(image_info,option+1);
6688                 break;
6689               }
6690             (void) SetImageOption(image_info,option+1,argv[i+1]);
6691             break;
6692           }
6693         if (LocaleCompare("limit",option+1) == 0)
6694           {
6695             MagickSizeType
6696               limit;
6697
6698             ResourceType
6699               type;
6700
6701             if (*option == '+')
6702               break;
6703             type=(ResourceType) ParseCommandOption(MagickResourceOptions,
6704               MagickFalse,argv[i+1]);
6705             limit=MagickResourceInfinity;
6706             if (LocaleCompare("unlimited",argv[i+2]) != 0)
6707               limit=(MagickSizeType) SiPrefixToDoubleInterval(argv[i+2],100.0);
6708             (void) SetMagickResourceLimit(type,limit);
6709             break;
6710           }
6711         if (LocaleCompare("list",option+1) == 0)
6712           {
6713             ssize_t
6714               list;
6715
6716             /*
6717               Display configuration list.
6718             */
6719             list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i+1]);
6720             switch (list)
6721             {
6722               case MagickCoderOptions:
6723               {
6724                 (void) ListCoderInfo((FILE *) NULL,exception);
6725                 break;
6726               }
6727               case MagickColorOptions:
6728               {
6729                 (void) ListColorInfo((FILE *) NULL,exception);
6730                 break;
6731               }
6732               case MagickConfigureOptions:
6733               {
6734                 (void) ListConfigureInfo((FILE *) NULL,exception);
6735                 break;
6736               }
6737               case MagickDelegateOptions:
6738               {
6739                 (void) ListDelegateInfo((FILE *) NULL,exception);
6740                 break;
6741               }
6742               case MagickFontOptions:
6743               {
6744                 (void) ListTypeInfo((FILE *) NULL,exception);
6745                 break;
6746               }
6747               case MagickFormatOptions:
6748               {
6749                 (void) ListMagickInfo((FILE *) NULL,exception);
6750                 break;
6751               }
6752               case MagickLocaleOptions:
6753               {
6754                 (void) ListLocaleInfo((FILE *) NULL,exception);
6755                 break;
6756               }
6757               case MagickLogOptions:
6758               {
6759                 (void) ListLogInfo((FILE *) NULL,exception);
6760                 break;
6761               }
6762               case MagickMagicOptions:
6763               {
6764                 (void) ListMagicInfo((FILE *) NULL,exception);
6765                 break;
6766               }
6767               case MagickMimeOptions:
6768               {
6769                 (void) ListMimeInfo((FILE *) NULL,exception);
6770                 break;
6771               }
6772               case MagickModuleOptions:
6773               {
6774                 (void) ListModuleInfo((FILE *) NULL,exception);
6775                 break;
6776               }
6777               case MagickPolicyOptions:
6778               {
6779                 (void) ListPolicyInfo((FILE *) NULL,exception);
6780                 break;
6781               }
6782               case MagickResourceOptions:
6783               {
6784                 (void) ListMagickResourceInfo((FILE *) NULL,exception);
6785                 break;
6786               }
6787               case MagickThresholdOptions:
6788               {
6789                 (void) ListThresholdMaps((FILE *) NULL,exception);
6790                 break;
6791               }
6792               default:
6793               {
6794                 (void) ListCommandOptions((FILE *) NULL,(CommandOption) list,
6795                   exception);
6796                 break;
6797               }
6798             }
6799             break;
6800           }
6801         if (LocaleCompare("log",option+1) == 0)
6802           {
6803             if (*option == '+')
6804               break;
6805             (void) SetLogFormat(argv[i+1]);
6806             break;
6807           }
6808         if (LocaleCompare("loop",option+1) == 0)
6809           {
6810             if (*option == '+')
6811               {
6812                 (void) SetImageOption(image_info,option+1,"0");
6813                 break;
6814               }
6815             (void) SetImageOption(image_info,option+1,argv[i+1]);
6816             break;
6817           }
6818         break;
6819       }
6820       case 'm':
6821       {
6822         if (LocaleCompare("matte",option+1) == 0)
6823           {
6824             if (*option == '+')
6825               {
6826                 (void) SetImageOption(image_info,option+1,"false");
6827                 break;
6828               }
6829             (void) SetImageOption(image_info,option+1,"true");
6830             break;
6831           }
6832         if (LocaleCompare("mattecolor",option+1) == 0)
6833           {
6834             if (*option == '+')
6835               {
6836                 (void) SetImageOption(image_info,option+1,argv[i+1]);
6837                 (void) QueryColorCompliance(MogrifyMatteColor,AllCompliance,
6838                   &image_info->matte_color,exception);
6839                 break;
6840               }
6841             (void) SetImageOption(image_info,option+1,argv[i+1]);
6842             (void) QueryColorCompliance(argv[i+1],AllCompliance,
6843               &image_info->matte_color,exception);
6844             break;
6845           }
6846         if (LocaleCompare("monitor",option+1) == 0)
6847           {
6848             (void) SetImageInfoProgressMonitor(image_info,MonitorProgress,
6849               (void *) NULL);
6850             break;
6851           }
6852         if (LocaleCompare("monochrome",option+1) == 0)
6853           {
6854             image_info->monochrome=(*option == '-') ? MagickTrue : MagickFalse;
6855             break;
6856           }
6857         break;
6858       }
6859       case 'o':
6860       {
6861         if (LocaleCompare("orient",option+1) == 0)
6862           {
6863             if (*option == '+')
6864               {
6865                 image_info->orientation=UndefinedOrientation;
6866                 (void) SetImageOption(image_info,option+1,"undefined");
6867                 break;
6868               }
6869             image_info->orientation=(OrientationType) ParseCommandOption(
6870               MagickOrientationOptions,MagickFalse,argv[i+1]);
6871             (void) SetImageOption(image_info,option+1,argv[i+1]);
6872             break;
6873           }
6874       }
6875       case 'p':
6876       {
6877         if (LocaleCompare("page",option+1) == 0)
6878           {
6879             char
6880               *canonical_page,
6881               page[MaxTextExtent];
6882
6883             const char
6884               *image_option;
6885
6886             MagickStatusType
6887               flags;
6888
6889             RectangleInfo
6890               geometry;
6891
6892             if (*option == '+')
6893               {
6894                 (void) DeleteImageOption(image_info,option+1);
6895                 (void) CloneString(&image_info->page,(char *) NULL);
6896                 break;
6897               }
6898             (void) ResetMagickMemory(&geometry,0,sizeof(geometry));
6899             image_option=GetImageOption(image_info,"page");
6900             if (image_option != (const char *) NULL)
6901               flags=ParseAbsoluteGeometry(image_option,&geometry);
6902             canonical_page=GetPageGeometry(argv[i+1]);
6903             flags=ParseAbsoluteGeometry(canonical_page,&geometry);
6904             canonical_page=DestroyString(canonical_page);
6905             (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu",
6906               (unsigned long) geometry.width,(unsigned long) geometry.height);
6907             if (((flags & XValue) != 0) || ((flags & YValue) != 0))
6908               (void) FormatLocaleString(page,MaxTextExtent,"%lux%lu%+ld%+ld",
6909                 (unsigned long) geometry.width,(unsigned long) geometry.height,
6910                 (long) geometry.x,(long) geometry.y);
6911             (void) SetImageOption(image_info,option+1,page);
6912             (void) CloneString(&image_info->page,page);
6913             break;
6914           }
6915         if (LocaleCompare("pen",option+1) == 0)
6916           {
6917             if (*option == '+')
6918               {
6919                 (void) SetImageOption(image_info,option+1,"none");
6920                 break;
6921               }
6922             (void) SetImageOption(image_info,option+1,argv[i+1]);
6923             break;
6924           }
6925         if (LocaleCompare("ping",option+1) == 0)
6926           {
6927             image_info->ping=(*option == '-') ? MagickTrue : MagickFalse;
6928             break;
6929           }
6930         if (LocaleCompare("pointsize",option+1) == 0)
6931           {
6932             if (*option == '+')
6933               geometry_info.rho=0.0;
6934             else
6935               (void) ParseGeometry(argv[i+1],&geometry_info);
6936             image_info->pointsize=geometry_info.rho;
6937             break;
6938           }
6939         if (LocaleCompare("precision",option+1) == 0)
6940           {
6941             (void) SetMagickPrecision(StringToInteger(argv[i+1]));
6942             break;
6943           }
6944         if (LocaleCompare("preview",option+1) == 0)
6945           {
6946             /*
6947               Preview image.
6948             */
6949             if (*option == '+')
6950               {
6951                 image_info->preview_type=UndefinedPreview;
6952                 break;
6953               }
6954             image_info->preview_type=(PreviewType) ParseCommandOption(
6955               MagickPreviewOptions,MagickFalse,argv[i+1]);
6956             break;
6957           }
6958         break;
6959       }
6960       case 'q':
6961       {
6962         if (LocaleCompare("quality",option+1) == 0)
6963           {
6964             /*
6965               Set image compression quality.
6966             */
6967             if (*option == '+')
6968               {
6969                 image_info->quality=UndefinedCompressionQuality;
6970                 (void) SetImageOption(image_info,option+1,"0");
6971                 break;
6972               }
6973             image_info->quality=StringToUnsignedLong(argv[i+1]);
6974             (void) SetImageOption(image_info,option+1,argv[i+1]);
6975             break;
6976           }
6977         if (LocaleCompare("quiet",option+1) == 0)
6978           {
6979             static WarningHandler
6980               warning_handler = (WarningHandler) NULL;
6981
6982             if (*option == '+')
6983               {
6984                 /*
6985                   Restore error or warning messages.
6986                 */
6987                 warning_handler=SetWarningHandler(warning_handler);
6988                 break;
6989               }
6990             /*
6991               Suppress error or warning messages.
6992             */
6993             warning_handler=SetWarningHandler((WarningHandler) NULL);
6994             break;
6995           }
6996         break;
6997       }
6998       case 'r':
6999       {
7000         if (LocaleCompare("red-primary",option+1) == 0)
7001           {
7002             if (*option == '+')
7003               {
7004                 (void) SetImageOption(image_info,option+1,"0.0");
7005                 break;
7006               }
7007             (void) SetImageOption(image_info,option+1,argv[i+1]);
7008             break;
7009           }
7010         break;
7011       }
7012       case 's':
7013       {
7014         if (LocaleCompare("sampling-factor",option+1) == 0)
7015           {
7016             /*
7017               Set image sampling factor.
7018             */
7019             if (*option == '+')
7020               {
7021                 if (image_info->sampling_factor != (char *) NULL)
7022                   image_info->sampling_factor=DestroyString(
7023                     image_info->sampling_factor);
7024                 break;
7025               }
7026             (void) CloneString(&image_info->sampling_factor,argv[i+1]);
7027             break;
7028           }
7029         if (LocaleCompare("scene",option+1) == 0)
7030           {
7031             /*
7032               Set image scene.
7033             */
7034             if (*option == '+')
7035               {
7036                 image_info->scene=0;
7037                 (void) SetImageOption(image_info,option+1,"0");
7038                 break;
7039               }
7040             image_info->scene=StringToUnsignedLong(argv[i+1]);
7041             (void) SetImageOption(image_info,option+1,argv[i+1]);
7042             break;
7043           }
7044         if (LocaleCompare("seed",option+1) == 0)
7045           {
7046             size_t
7047               seed;
7048
7049             if (*option == '+')
7050               {
7051                 seed=(size_t) time((time_t *) NULL);
7052                 SeedPseudoRandomGenerator(seed);
7053                 break;
7054               }
7055             seed=StringToUnsignedLong(argv[i+1]);
7056             SeedPseudoRandomGenerator(seed);
7057             break;
7058           }
7059         if (LocaleCompare("size",option+1) == 0)
7060           {
7061             if (*option == '+')
7062               {
7063                 if (image_info->size != (char *) NULL)
7064                   image_info->size=DestroyString(image_info->size);
7065                 break;
7066               }
7067             (void) CloneString(&image_info->size,argv[i+1]);
7068             break;
7069           }
7070         if (LocaleCompare("stroke",option+1) == 0)
7071           {
7072             if (*option == '+')
7073               {
7074                 (void) SetImageOption(image_info,option+1,"none");
7075                 break;
7076               }
7077             (void) SetImageOption(image_info,option+1,argv[i+1]);
7078             break;
7079           }
7080         if (LocaleCompare("strokewidth",option+1) == 0)
7081           {
7082             if (*option == '+')
7083               {
7084                 (void) SetImageOption(image_info,option+1,"0");
7085                 break;
7086               }
7087             (void) SetImageOption(image_info,option+1,argv[i+1]);
7088             break;
7089           }
7090         if (LocaleCompare("synchronize",option+1) == 0)
7091           {
7092             if (*option == '+')
7093               {
7094                 image_info->synchronize=MagickFalse;
7095                 break;
7096               }
7097             image_info->synchronize=MagickTrue;
7098             break;
7099           }
7100         break;
7101       }
7102       case 't':
7103       {
7104         if (LocaleCompare("taint",option+1) == 0)
7105           {
7106             if (*option == '+')
7107               {
7108                 (void) SetImageOption(image_info,option+1,"false");
7109                 break;
7110               }
7111             (void) SetImageOption(image_info,option+1,"true");
7112             break;
7113           }
7114         if (LocaleCompare("texture",option+1) == 0)
7115           {
7116             if (*option == '+')
7117               {
7118                 if (image_info->texture != (char *) NULL)
7119                   image_info->texture=DestroyString(image_info->texture);
7120                 break;
7121               }
7122             (void) CloneString(&image_info->texture,argv[i+1]);
7123             break;
7124           }
7125         if (LocaleCompare("tile-offset",option+1) == 0)
7126           {
7127             if (*option == '+')
7128               {
7129                 (void) SetImageOption(image_info,option+1,"0");
7130                 break;
7131               }
7132             (void) SetImageOption(image_info,option+1,argv[i+1]);
7133             break;
7134           }
7135         if (LocaleCompare("transparent-color",option+1) == 0)
7136           {
7137             if (*option == '+')
7138               {
7139                 (void) QueryColorCompliance("none",AllCompliance,
7140                   &image_info->transparent_color,exception);
7141                 (void) SetImageOption(image_info,option+1,"none");
7142                 break;
7143               }
7144             (void) QueryColorCompliance(argv[i+1],AllCompliance,
7145               &image_info->transparent_color,exception);
7146             (void) SetImageOption(image_info,option+1,argv[i+1]);
7147             break;
7148           }
7149         if (LocaleCompare("type",option+1) == 0)
7150           {
7151             if (*option == '+')
7152               {
7153                 image_info->type=UndefinedType;
7154                 (void) SetImageOption(image_info,option+1,"undefined");
7155                 break;
7156               }
7157             image_info->type=(ImageType) ParseCommandOption(MagickTypeOptions,
7158               MagickFalse,argv[i+1]);
7159             (void) SetImageOption(image_info,option+1,argv[i+1]);
7160             break;
7161           }
7162         break;
7163       }
7164       case 'u':
7165       {
7166         if (LocaleCompare("undercolor",option+1) == 0)
7167           {
7168             if (*option == '+')
7169               {
7170                 (void) DeleteImageOption(image_info,option+1);
7171                 break;
7172               }
7173             (void) SetImageOption(image_info,option+1,argv[i+1]);
7174             break;
7175           }
7176         if (LocaleCompare("units",option+1) == 0)
7177           {
7178             if (*option == '+')
7179               {
7180                 image_info->units=UndefinedResolution;
7181                 (void) SetImageOption(image_info,option+1,"undefined");
7182                 break;
7183               }
7184             image_info->units=(ResolutionType) ParseCommandOption(
7185               MagickResolutionOptions,MagickFalse,argv[i+1]);
7186             (void) SetImageOption(image_info,option+1,argv[i+1]);
7187             break;
7188           }
7189         break;
7190       }
7191       case 'v':
7192       {
7193         if (LocaleCompare("verbose",option+1) == 0)
7194           {
7195             if (*option == '+')
7196               {
7197                 image_info->verbose=MagickFalse;
7198                 break;
7199               }
7200             image_info->verbose=MagickTrue;
7201             image_info->ping=MagickFalse;
7202             break;
7203           }
7204         if (LocaleCompare("view",option+1) == 0)
7205           {
7206             if (*option == '+')
7207               {
7208                 if (image_info->view != (char *) NULL)
7209                   image_info->view=DestroyString(image_info->view);
7210                 break;
7211               }
7212             (void) CloneString(&image_info->view,argv[i+1]);
7213             break;
7214           }
7215         if (LocaleCompare("virtual-pixel",option+1) == 0)
7216           {
7217             if (*option == '+')
7218               {
7219                 image_info->virtual_pixel_method=UndefinedVirtualPixelMethod;
7220                 (void) SetImageOption(image_info,option+1,"undefined");
7221                 break;
7222               }
7223             image_info->virtual_pixel_method=(VirtualPixelMethod)
7224               ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
7225               argv[i+1]);
7226             (void) SetImageOption(image_info,option+1,argv[i+1]);
7227             break;
7228           }
7229         break;
7230       }
7231       case 'w':
7232       {
7233         if (LocaleCompare("white-point",option+1) == 0)
7234           {
7235             if (*option == '+')
7236               {
7237                 (void) SetImageOption(image_info,option+1,"0.0");
7238                 break;
7239               }
7240             (void) SetImageOption(image_info,option+1,argv[i+1]);
7241             break;
7242           }
7243         break;
7244       }
7245       default:
7246         break;
7247     }
7248     i+=count;
7249   }
7250   return(MagickTrue);
7251 }
7252 \f
7253 /*
7254 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7255 %                                                                             %
7256 %                                                                             %
7257 %                                                                             %
7258 +     M o g r i f y I m a g e L i s t                                         %
7259 %                                                                             %
7260 %                                                                             %
7261 %                                                                             %
7262 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7263 %
7264 %  MogrifyImageList() applies any command line options that might affect the
7265 %  entire image list (e.g. -append, -coalesce, etc.).
7266 %
7267 %  The format of the MogrifyImage method is:
7268 %
7269 %      MagickBooleanType MogrifyImageList(ImageInfo *image_info,const int argc,
7270 %        const char **argv,Image **images,ExceptionInfo *exception)
7271 %
7272 %  A description of each parameter follows:
7273 %
7274 %    o image_info: the image info..
7275 %
7276 %    o argc: Specifies a pointer to an integer describing the number of
7277 %      elements in the argument vector.
7278 %
7279 %    o argv: Specifies a pointer to a text array containing the command line
7280 %      arguments.
7281 %
7282 %    o images: pointer to pointer of the first image in image list.
7283 %
7284 %    o exception: return any errors or warnings in this structure.
7285 %
7286 */
7287 WandExport MagickBooleanType MogrifyImageList(ImageInfo *image_info,
7288   const int argc,const char **argv,Image **images,ExceptionInfo *exception)
7289 {
7290   const char
7291     *option;
7292
7293   ImageInfo
7294     *mogrify_info;
7295
7296   MagickStatusType
7297     status;
7298
7299   PixelInterpolateMethod
7300    interpolate_method;
7301
7302   QuantizeInfo
7303     *quantize_info;
7304
7305   register ssize_t
7306     i;
7307
7308   ssize_t
7309     count,
7310     index;
7311
7312   /*
7313     Apply options to the image list.
7314   */
7315   assert(image_info != (ImageInfo *) NULL);
7316   assert(image_info->signature == MagickSignature);
7317   assert(images != (Image **) NULL);
7318   assert((*images)->previous == (Image *) NULL);
7319   assert((*images)->signature == MagickSignature);
7320   if ((*images)->debug != MagickFalse)
7321     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
7322       (*images)->filename);
7323   if ((argc <= 0) || (*argv == (char *) NULL))
7324     return(MagickTrue);
7325   interpolate_method=UndefinedInterpolatePixel;
7326   mogrify_info=CloneImageInfo(image_info);
7327   quantize_info=AcquireQuantizeInfo(mogrify_info);
7328   status=MagickTrue;
7329   for (i=0; i < (ssize_t) argc; i++)
7330   {
7331     if (*images == (Image *) NULL)
7332       break;
7333     option=argv[i];
7334     if (IsCommandOption(option) == MagickFalse)
7335       continue;
7336     count=ParseCommandOption(MagickCommandOptions,MagickFalse,option);
7337     count=MagickMax(count,0L);
7338     if ((i+count) >= (ssize_t) argc)
7339       break;
7340     status=MogrifyImageInfo(mogrify_info,(int) count+1,argv+i,exception);
7341     switch (*(option+1))
7342     {
7343       case 'a':
7344       {
7345         if (LocaleCompare("affinity",option+1) == 0)
7346           {
7347             (void) SyncImagesSettings(mogrify_info,*images,exception);
7348             if (*option == '+')
7349               {
7350                 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7351                   exception);
7352                 break;
7353               }
7354             i++;
7355             break;
7356           }
7357         if (LocaleCompare("append",option+1) == 0)
7358           {
7359             Image
7360               *append_image;
7361
7362             (void) SyncImagesSettings(mogrify_info,*images,exception);
7363             append_image=AppendImages(*images,*option == '-' ? MagickTrue :
7364               MagickFalse,exception);
7365             if (append_image == (Image *) NULL)
7366               {
7367                 status=MagickFalse;
7368                 break;
7369               }
7370             *images=DestroyImageList(*images);
7371             *images=append_image;
7372             break;
7373           }
7374         if (LocaleCompare("average",option+1) == 0)
7375           {
7376             Image
7377               *average_image;
7378
7379             /*
7380               Average an image sequence (deprecated).
7381             */
7382             (void) SyncImagesSettings(mogrify_info,*images,exception);
7383             average_image=EvaluateImages(*images,MeanEvaluateOperator,
7384               exception);
7385             if (average_image == (Image *) NULL)
7386               {
7387                 status=MagickFalse;
7388                 break;
7389               }
7390             *images=DestroyImageList(*images);
7391             *images=average_image;
7392             break;
7393           }
7394         break;
7395       }
7396       case 'c':
7397       {
7398         if (LocaleCompare("channel",option+1) == 0)
7399           {
7400             ChannelType
7401               channel;
7402
7403             if (*option == '+')
7404               {
7405                 channel=DefaultChannels;
7406                 break;
7407               }
7408             channel=(ChannelType) ParseChannelOption(argv[i+1]);
7409             SetPixelChannelMapMask(*images,channel);
7410             break;
7411           }
7412         if (LocaleCompare("clut",option+1) == 0)
7413           {
7414             Image
7415               *clut_image,
7416               *image;
7417
7418             (void) SyncImagesSettings(mogrify_info,*images,exception);
7419             image=RemoveFirstImageFromList(images);
7420             clut_image=RemoveFirstImageFromList(images);
7421             if (clut_image == (Image *) NULL)
7422               {
7423                 status=MagickFalse;
7424                 break;
7425               }
7426             (void) ClutImage(image,clut_image,interpolate_method,exception);
7427             clut_image=DestroyImage(clut_image);
7428             *images=DestroyImageList(*images);
7429             *images=image;
7430             break;
7431           }
7432         if (LocaleCompare("coalesce",option+1) == 0)
7433           {
7434             Image
7435               *coalesce_image;
7436
7437             (void) SyncImagesSettings(mogrify_info,*images,exception);
7438             coalesce_image=CoalesceImages(*images,exception);
7439             if (coalesce_image == (Image *) NULL)
7440               {
7441                 status=MagickFalse;
7442                 break;
7443               }
7444             *images=DestroyImageList(*images);
7445             *images=coalesce_image;
7446             break;
7447           }
7448         if (LocaleCompare("combine",option+1) == 0)
7449           {
7450             Image
7451               *combine_image;
7452
7453             (void) SyncImagesSettings(mogrify_info,*images,exception);
7454             combine_image=CombineImages(*images,exception);
7455             if (combine_image == (Image *) NULL)
7456               {
7457                 status=MagickFalse;
7458                 break;
7459               }
7460             *images=DestroyImageList(*images);
7461             *images=combine_image;
7462             break;
7463           }
7464         if (LocaleCompare("composite",option+1) == 0)
7465           {
7466             Image
7467               *mask_image,
7468               *composite_image,
7469               *image;
7470
7471             RectangleInfo
7472               geometry;
7473
7474             (void) SyncImagesSettings(mogrify_info,*images,exception);
7475             image=RemoveFirstImageFromList(images);
7476             composite_image=RemoveFirstImageFromList(images);
7477             if (composite_image == (Image *) NULL)
7478               {
7479                 status=MagickFalse;
7480                 break;
7481               }
7482             (void) TransformImage(&composite_image,(char *) NULL,
7483               composite_image->geometry,exception);
7484             SetGeometry(composite_image,&geometry);
7485             (void) ParseAbsoluteGeometry(composite_image->geometry,&geometry);
7486             GravityAdjustGeometry(image->columns,image->rows,image->gravity,
7487               &geometry);
7488             mask_image=RemoveFirstImageFromList(images);
7489             if (mask_image != (Image *) NULL)
7490               {
7491                 if ((image->compose == DisplaceCompositeOp) ||
7492                     (image->compose == DistortCompositeOp))
7493                   {
7494                     /*
7495                       Merge Y displacement into X displacement image.
7496                     */
7497                     (void) CompositeImage(composite_image,CopyGreenCompositeOp,
7498                       mask_image,0,0,exception);
7499                     mask_image=DestroyImage(mask_image);
7500                   }
7501                 else
7502                   {
7503                     /*
7504                       Set a blending mask for the composition.
7505                       Posible error, what if image->mask already set.
7506                     */
7507                     image->mask=mask_image;
7508                     (void) NegateImage(image->mask,MagickFalse,exception);
7509                   }
7510               }
7511             (void) CompositeImage(image,image->compose,composite_image,
7512               geometry.x,geometry.y,exception);
7513             if (mask_image != (Image *) NULL)
7514               mask_image=image->mask=DestroyImage(image->mask);
7515             composite_image=DestroyImage(composite_image);
7516             *images=DestroyImageList(*images);
7517             *images=image;
7518             break;
7519           }
7520         break;
7521       }
7522       case 'd':
7523       {
7524         if (LocaleCompare("deconstruct",option+1) == 0)
7525           {
7526             Image
7527               *deconstruct_image;
7528
7529             (void) SyncImagesSettings(mogrify_info,*images,exception);
7530             deconstruct_image=CompareImagesLayers(*images,CompareAnyLayer,
7531               exception);
7532             if (deconstruct_image == (Image *) NULL)
7533               {
7534                 status=MagickFalse;
7535                 break;
7536               }
7537             *images=DestroyImageList(*images);
7538             *images=deconstruct_image;
7539             break;
7540           }
7541         if (LocaleCompare("delete",option+1) == 0)
7542           {
7543             if (*option == '+')
7544               DeleteImages(images,"-1",exception);
7545             else
7546               DeleteImages(images,argv[i+1],exception);
7547             break;
7548           }
7549         if (LocaleCompare("dither",option+1) == 0)
7550           {
7551             if (*option == '+')
7552               {
7553                 quantize_info->dither=MagickFalse;
7554                 break;
7555               }
7556             quantize_info->dither=MagickTrue;
7557             quantize_info->dither_method=(DitherMethod) ParseCommandOption(
7558               MagickDitherOptions,MagickFalse,argv[i+1]);
7559             break;
7560           }
7561         if (LocaleCompare("duplicate",option+1) == 0)
7562           {
7563             Image
7564               *duplicate_images;
7565
7566             if (*option == '+')
7567               duplicate_images=DuplicateImages(*images,1,"-1",exception);
7568             else
7569               {
7570                 const char
7571                   *p;
7572
7573                 size_t
7574                   number_duplicates;
7575
7576                 number_duplicates=(size_t) StringToLong(argv[i+1]);
7577                 p=strchr(argv[i+1],',');
7578                 if (p == (const char *) NULL)
7579                   duplicate_images=DuplicateImages(*images,number_duplicates,
7580                     "-1",exception);
7581                 else
7582                   duplicate_images=DuplicateImages(*images,number_duplicates,p,
7583                     exception);
7584               }
7585             AppendImageToList(images, duplicate_images);
7586             (void) SyncImagesSettings(mogrify_info,*images,exception);
7587             break;
7588           }
7589         break;
7590       }
7591       case 'e':
7592       {
7593         if (LocaleCompare("evaluate-sequence",option+1) == 0)
7594           {
7595             Image
7596               *evaluate_image;
7597
7598             MagickEvaluateOperator
7599               op;
7600
7601             (void) SyncImageSettings(mogrify_info,*images,exception);
7602             op=(MagickEvaluateOperator) ParseCommandOption(
7603               MagickEvaluateOptions,MagickFalse,argv[i+1]);
7604             evaluate_image=EvaluateImages(*images,op,exception);
7605             if (evaluate_image == (Image *) NULL)
7606               {
7607                 status=MagickFalse;
7608                 break;
7609               }
7610             *images=DestroyImageList(*images);
7611             *images=evaluate_image;
7612             break;
7613           }
7614         break;
7615       }
7616       case 'f':
7617       {
7618         if (LocaleCompare("fft",option+1) == 0)
7619           {
7620             Image
7621               *fourier_image;
7622
7623             /*
7624               Implements the discrete Fourier transform (DFT).
7625             */
7626             (void) SyncImageSettings(mogrify_info,*images,exception);
7627             fourier_image=ForwardFourierTransformImage(*images,*option == '-' ?
7628               MagickTrue : MagickFalse,exception);
7629             if (fourier_image == (Image *) NULL)
7630               break;
7631             *images=DestroyImage(*images);
7632             *images=fourier_image;
7633             break;
7634           }
7635         if (LocaleCompare("flatten",option+1) == 0)
7636           {
7637             Image
7638               *flatten_image;
7639
7640             (void) SyncImagesSettings(mogrify_info,*images,exception);
7641             flatten_image=MergeImageLayers(*images,FlattenLayer,exception);
7642             if (flatten_image == (Image *) NULL)
7643               break;
7644             *images=DestroyImageList(*images);
7645             *images=flatten_image;
7646             break;
7647           }
7648         if (LocaleCompare("fx",option+1) == 0)
7649           {
7650             Image
7651               *fx_image;
7652
7653             (void) SyncImagesSettings(mogrify_info,*images,exception);
7654             fx_image=FxImage(*images,argv[i+1],exception);
7655             if (fx_image == (Image *) NULL)
7656               {
7657                 status=MagickFalse;
7658                 break;
7659               }
7660             *images=DestroyImageList(*images);
7661             *images=fx_image;
7662             break;
7663           }
7664         break;
7665       }
7666       case 'h':
7667       {
7668         if (LocaleCompare("hald-clut",option+1) == 0)
7669           {
7670             Image
7671               *hald_image,
7672               *image;
7673
7674             (void) SyncImagesSettings(mogrify_info,*images,exception);
7675             image=RemoveFirstImageFromList(images);
7676             hald_image=RemoveFirstImageFromList(images);
7677             if (hald_image == (Image *) NULL)
7678               {
7679                 status=MagickFalse;
7680                 break;
7681               }
7682             (void) HaldClutImage(image,hald_image,exception);
7683             hald_image=DestroyImage(hald_image);
7684             if (*images != (Image *) NULL)
7685               *images=DestroyImageList(*images);
7686             *images=image;
7687             break;
7688           }
7689         break;
7690       }
7691       case 'i':
7692       {
7693         if (LocaleCompare("ift",option+1) == 0)
7694           {
7695             Image
7696               *fourier_image,
7697               *magnitude_image,
7698               *phase_image;
7699
7700             /*
7701               Implements the inverse fourier discrete Fourier transform (DFT).
7702             */
7703             (void) SyncImagesSettings(mogrify_info,*images,exception);
7704             magnitude_image=RemoveFirstImageFromList(images);
7705             phase_image=RemoveFirstImageFromList(images);
7706             if (phase_image == (Image *) NULL)
7707               {
7708                 status=MagickFalse;
7709                 break;
7710               }
7711             fourier_image=InverseFourierTransformImage(magnitude_image,
7712               phase_image,*option == '-' ? MagickTrue : MagickFalse,exception);
7713             if (fourier_image == (Image *) NULL)
7714               break;
7715             if (*images != (Image *) NULL)
7716               *images=DestroyImage(*images);
7717             *images=fourier_image;
7718             break;
7719           }
7720         if (LocaleCompare("insert",option+1) == 0)
7721           {
7722             Image
7723               *p,
7724               *q;
7725
7726             index=0;
7727             if (*option != '+')
7728               index=(ssize_t) StringToLong(argv[i+1]);
7729             p=RemoveLastImageFromList(images);
7730             if (p == (Image *) NULL)
7731               {
7732                 (void) ThrowMagickException(exception,GetMagickModule(),
7733                   OptionError,"NoSuchImage","`%s'",argv[i+1]);
7734                 status=MagickFalse;
7735                 break;
7736               }
7737             q=p;
7738             if (index == 0)
7739               PrependImageToList(images,q);
7740             else
7741               if (index == (ssize_t) GetImageListLength(*images))
7742                 AppendImageToList(images,q);
7743               else
7744                 {
7745                    q=GetImageFromList(*images,index-1);
7746                    if (q == (Image *) NULL)
7747                      {
7748                        (void) ThrowMagickException(exception,GetMagickModule(),
7749                          OptionError,"NoSuchImage","`%s'",argv[i+1]);
7750                        status=MagickFalse;
7751                        break;
7752                      }
7753                   InsertImageInList(&q,p);
7754                 }
7755             *images=GetFirstImageInList(q);
7756             break;
7757           }
7758         if (LocaleCompare("interpolate",option+1) == 0)
7759           {
7760             interpolate_method=(PixelInterpolateMethod) ParseCommandOption(
7761               MagickInterpolateOptions,MagickFalse,argv[i+1]);
7762             break;
7763           }
7764         break;
7765       }
7766       case 'l':
7767       {
7768         if (LocaleCompare("layers",option+1) == 0)
7769           {
7770             Image
7771               *layers;
7772
7773             ImageLayerMethod
7774               method;
7775
7776             (void) SyncImagesSettings(mogrify_info,*images,exception);
7777             layers=(Image *) NULL;
7778             method=(ImageLayerMethod) ParseCommandOption(MagickLayerOptions,
7779               MagickFalse,argv[i+1]);
7780             switch (method)
7781             {
7782               case CoalesceLayer:
7783               {
7784                 layers=CoalesceImages(*images,exception);
7785                 break;
7786               }
7787               case CompareAnyLayer:
7788               case CompareClearLayer:
7789               case CompareOverlayLayer:
7790               default:
7791               {
7792                 layers=CompareImagesLayers(*images,method,exception);
7793                 break;
7794               }
7795               case MergeLayer:
7796               case FlattenLayer:
7797               case MosaicLayer:
7798               case TrimBoundsLayer:
7799               {
7800                 layers=MergeImageLayers(*images,method,exception);
7801                 break;
7802               }
7803               case DisposeLayer:
7804               {
7805                 layers=DisposeImages(*images,exception);
7806                 break;
7807               }
7808               case OptimizeImageLayer:
7809               {
7810                 layers=OptimizeImageLayers(*images,exception);
7811                 break;
7812               }
7813               case OptimizePlusLayer:
7814               {
7815                 layers=OptimizePlusImageLayers(*images,exception);
7816                 break;
7817               }
7818               case OptimizeTransLayer:
7819               {
7820                 OptimizeImageTransparency(*images,exception);
7821                 break;
7822               }
7823               case RemoveDupsLayer:
7824               {
7825                 RemoveDuplicateLayers(images,exception);
7826                 break;
7827               }
7828               case RemoveZeroLayer:
7829               {
7830                 RemoveZeroDelayLayers(images,exception);
7831                 break;
7832               }
7833               case OptimizeLayer:
7834               {
7835                 /*
7836                   General Purpose, GIF Animation Optimizer.
7837                 */
7838                 layers=CoalesceImages(*images,exception);
7839                 if (layers == (Image *) NULL)
7840                   {
7841                     status=MagickFalse;
7842                     break;
7843                   }
7844                 *images=DestroyImageList(*images);
7845                 *images=layers;
7846                 layers=OptimizeImageLayers(*images,exception);
7847                 if (layers == (Image *) NULL)
7848                   {
7849                     status=MagickFalse;
7850                     break;
7851                   }
7852                 *images=DestroyImageList(*images);
7853                 *images=layers;
7854                 layers=(Image *) NULL;
7855                 OptimizeImageTransparency(*images,exception);
7856                 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7857                   exception);
7858                 break;
7859               }
7860               case CompositeLayer:
7861               {
7862                 CompositeOperator
7863                   compose;
7864
7865                 Image
7866                   *source;
7867
7868                 RectangleInfo
7869                   geometry;
7870
7871                 /*
7872                   Split image sequence at the first 'NULL:' image.
7873                 */
7874                 source=(*images);
7875                 while (source != (Image *) NULL)
7876                 {
7877                   source=GetNextImageInList(source);
7878                   if ((source != (Image *) NULL) &&
7879                       (LocaleCompare(source->magick,"NULL") == 0))
7880                     break;
7881                 }
7882                 if (source != (Image *) NULL)
7883                   {
7884                     if ((GetPreviousImageInList(source) == (Image *) NULL) ||
7885                         (GetNextImageInList(source) == (Image *) NULL))
7886                       source=(Image *) NULL;
7887                     else
7888                       {
7889                         /*
7890                           Separate the two lists, junk the null: image.
7891                         */
7892                         source=SplitImageList(source->previous);
7893                         DeleteImageFromList(&source);
7894                       }
7895                   }
7896                 if (source == (Image *) NULL)
7897                   {
7898                     (void) ThrowMagickException(exception,GetMagickModule(),
7899                       OptionError,"MissingNullSeparator","layers Composite");
7900                     status=MagickFalse;
7901                     break;
7902                   }
7903                 /*
7904                   Adjust offset with gravity and virtual canvas.
7905                 */
7906                 SetGeometry(*images,&geometry);
7907                 (void) ParseAbsoluteGeometry((*images)->geometry,&geometry);
7908                 geometry.width=source->page.width != 0 ?
7909                   source->page.width : source->columns;
7910                 geometry.height=source->page.height != 0 ?
7911                  source->page.height : source->rows;
7912                 GravityAdjustGeometry((*images)->page.width != 0 ?
7913                   (*images)->page.width : (*images)->columns,
7914                   (*images)->page.height != 0 ? (*images)->page.height :
7915                   (*images)->rows,(*images)->gravity,&geometry);
7916                 compose=OverCompositeOp;
7917                 option=GetImageOption(mogrify_info,"compose");
7918                 if (option != (const char *) NULL)
7919                   compose=(CompositeOperator) ParseCommandOption(
7920                     MagickComposeOptions,MagickFalse,option);
7921                 CompositeLayers(*images,compose,source,geometry.x,geometry.y,
7922                   exception);
7923                 source=DestroyImageList(source);
7924                 break;
7925               }
7926             }
7927             if (layers == (Image *) NULL)
7928               break;
7929             *images=DestroyImageList(*images);
7930             *images=layers;
7931             break;
7932           }
7933         break;
7934       }
7935       case 'm':
7936       {
7937         if (LocaleCompare("map",option+1) == 0)
7938           {
7939             (void) SyncImagesSettings(mogrify_info,*images,exception);
7940             if (*option == '+')
7941               {
7942                 (void) RemapImages(quantize_info,*images,(Image *) NULL,
7943                   exception);
7944                 break;
7945               }
7946             i++;
7947             break;
7948           }
7949         if (LocaleCompare("maximum",option+1) == 0)
7950           {
7951             Image
7952               *maximum_image;
7953
7954             /*
7955               Maximum image sequence (deprecated).
7956             */
7957             (void) SyncImagesSettings(mogrify_info,*images,exception);
7958             maximum_image=EvaluateImages(*images,MaxEvaluateOperator,exception);
7959             if (maximum_image == (Image *) NULL)
7960               {
7961                 status=MagickFalse;
7962                 break;
7963               }
7964             *images=DestroyImageList(*images);
7965             *images=maximum_image;
7966             break;
7967           }
7968         if (LocaleCompare("minimum",option+1) == 0)
7969           {
7970             Image
7971               *minimum_image;
7972
7973             /*
7974               Minimum image sequence (deprecated).
7975             */
7976             (void) SyncImagesSettings(mogrify_info,*images,exception);
7977             minimum_image=EvaluateImages(*images,MinEvaluateOperator,exception);
7978             if (minimum_image == (Image *) NULL)
7979               {
7980                 status=MagickFalse;
7981                 break;
7982               }
7983             *images=DestroyImageList(*images);
7984             *images=minimum_image;
7985             break;
7986           }
7987         if (LocaleCompare("morph",option+1) == 0)
7988           {
7989             Image
7990               *morph_image;
7991
7992             (void) SyncImagesSettings(mogrify_info,*images,exception);
7993             morph_image=MorphImages(*images,StringToUnsignedLong(argv[i+1]),
7994               exception);
7995             if (morph_image == (Image *) NULL)
7996               {
7997                 status=MagickFalse;
7998                 break;
7999               }
8000             *images=DestroyImageList(*images);
8001             *images=morph_image;
8002             break;
8003           }
8004         if (LocaleCompare("mosaic",option+1) == 0)
8005           {
8006             Image
8007               *mosaic_image;
8008
8009             (void) SyncImagesSettings(mogrify_info,*images,exception);
8010             mosaic_image=MergeImageLayers(*images,MosaicLayer,exception);
8011             if (mosaic_image == (Image *) NULL)
8012               {
8013                 status=MagickFalse;
8014                 break;
8015               }
8016             *images=DestroyImageList(*images);
8017             *images=mosaic_image;
8018             break;
8019           }
8020         break;
8021       }
8022       case 'p':
8023       {
8024         if (LocaleCompare("print",option+1) == 0)
8025           {
8026             char
8027               *string;
8028
8029             (void) SyncImagesSettings(mogrify_info,*images,exception);
8030             string=InterpretImageProperties(mogrify_info,*images,argv[i+1],
8031               exception);
8032             if (string == (char *) NULL)
8033               break;
8034             (void) FormatLocaleFile(stdout,"%s",string);
8035             string=DestroyString(string);
8036           }
8037         if (LocaleCompare("process",option+1) == 0)
8038           {
8039             char
8040               **arguments;
8041
8042             int
8043               j,
8044               number_arguments;
8045
8046             (void) SyncImagesSettings(mogrify_info,*images,exception);
8047             arguments=StringToArgv(argv[i+1],&number_arguments);
8048             if (arguments == (char **) NULL)
8049               break;
8050             if ((argc > 1) && (strchr(arguments[1],'=') != (char *) NULL))
8051               {
8052                 char
8053                   breaker,
8054                   quote,
8055                   *token;
8056
8057                 const char
8058                   *arguments;
8059
8060                 int
8061                   next,
8062                   status;
8063
8064                 size_t
8065                   length;
8066
8067                 TokenInfo
8068                   *token_info;
8069
8070                 /*
8071                   Support old style syntax, filter="-option arg".
8072                 */
8073                 length=strlen(argv[i+1]);
8074                 token=(char *) NULL;
8075                 if (~length >= (MaxTextExtent-1))
8076                   token=(char *) AcquireQuantumMemory(length+MaxTextExtent,
8077                     sizeof(*token));
8078                 if (token == (char *) NULL)
8079                   break;
8080                 next=0;
8081                 arguments=argv[i+1];
8082                 token_info=AcquireTokenInfo();
8083                 status=Tokenizer(token_info,0,token,length,arguments,"","=",
8084                   "\"",'\0',&breaker,&next,&quote);
8085                 token_info=DestroyTokenInfo(token_info);
8086                 if (status == 0)
8087                   {
8088                     const char
8089                       *argv;
8090
8091                     argv=(&(arguments[next]));
8092                     (void) InvokeDynamicImageFilter(token,&(*images),1,&argv,
8093                       exception);
8094                   }
8095                 token=DestroyString(token);
8096                 break;
8097               }
8098             (void) SubstituteString(&arguments[1],"-","");
8099             (void) InvokeDynamicImageFilter(arguments[1],&(*images),
8100               number_arguments-2,(const char **) arguments+2,exception);
8101             for (j=0; j < number_arguments; j++)
8102               arguments[j]=DestroyString(arguments[j]);
8103             arguments=(char **) RelinquishMagickMemory(arguments);
8104             break;
8105           }
8106         break;
8107       }
8108       case 'r':
8109       {
8110         if (LocaleCompare("reverse",option+1) == 0)
8111           {
8112             ReverseImageList(images);
8113             break;
8114           }
8115         break;
8116       }
8117       case 's':
8118       {
8119         if (LocaleCompare("smush",option+1) == 0)
8120           {
8121             Image
8122               *smush_image;
8123
8124             ssize_t
8125               offset;
8126
8127             (void) SyncImagesSettings(mogrify_info,*images,exception);
8128             offset=(ssize_t) StringToLong(argv[i+1]);
8129             smush_image=SmushImages(*images,*option == '-' ? MagickTrue :
8130               MagickFalse,offset,exception);
8131             if (smush_image == (Image *) NULL)
8132               {
8133                 status=MagickFalse;
8134                 break;
8135               }
8136             *images=DestroyImageList(*images);
8137             *images=smush_image;
8138             break;
8139           }
8140         if (LocaleCompare("swap",option+1) == 0)
8141           {
8142             Image
8143               *p,
8144               *q,
8145               *swap;
8146
8147             ssize_t
8148               swap_index;
8149
8150             index=(-1);
8151             swap_index=(-2);
8152             if (*option != '+')
8153               {
8154                 GeometryInfo
8155                   geometry_info;
8156
8157                 MagickStatusType
8158                   flags;
8159
8160                 swap_index=(-1);
8161                 flags=ParseGeometry(argv[i+1],&geometry_info);
8162                 index=(ssize_t) geometry_info.rho;
8163                 if ((flags & SigmaValue) != 0)
8164                   swap_index=(ssize_t) geometry_info.sigma;
8165               }
8166             p=GetImageFromList(*images,index);
8167             q=GetImageFromList(*images,swap_index);
8168             if ((p == (Image *) NULL) || (q == (Image *) NULL))
8169               {
8170                 (void) ThrowMagickException(exception,GetMagickModule(),
8171                   OptionError,"NoSuchImage","`%s'",(*images)->filename);
8172                 status=MagickFalse;
8173                 break;
8174               }
8175             if (p == q)
8176               break;
8177             swap=CloneImage(p,0,0,MagickTrue,exception);
8178             ReplaceImageInList(&p,CloneImage(q,0,0,MagickTrue,exception));
8179             ReplaceImageInList(&q,swap);
8180             *images=GetFirstImageInList(q);
8181             break;
8182           }
8183         break;
8184       }
8185       case 'w':
8186       {
8187         if (LocaleCompare("write",option+1) == 0)
8188           {
8189             char
8190               key[MaxTextExtent];
8191
8192             Image
8193               *write_images;
8194
8195             ImageInfo
8196               *write_info;
8197
8198             (void) SyncImagesSettings(mogrify_info,*images,exception);
8199             (void) FormatLocaleString(key,MaxTextExtent,"cache:%s",argv[i+1]);
8200             (void) DeleteImageRegistry(key);
8201             write_images=(*images);
8202             if (*option == '+')
8203               write_images=CloneImageList(*images,exception);
8204             write_info=CloneImageInfo(mogrify_info);
8205             status&=WriteImages(write_info,write_images,argv[i+1],exception);
8206             write_info=DestroyImageInfo(write_info);
8207             if (*option == '+')
8208               write_images=DestroyImageList(write_images);
8209             break;
8210           }
8211         break;
8212       }
8213       default:
8214         break;
8215     }
8216     i+=count;
8217   }
8218   quantize_info=DestroyQuantizeInfo(quantize_info);
8219   mogrify_info=DestroyImageInfo(mogrify_info);
8220   status&=MogrifyImageInfo(image_info,argc,argv,exception);
8221   return(status != 0 ? MagickTrue : MagickFalse);
8222 }
8223 \f
8224 /*
8225 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8226 %                                                                             %
8227 %                                                                             %
8228 %                                                                             %
8229 +     M o g r i f y I m a g e s                                               %
8230 %                                                                             %
8231 %                                                                             %
8232 %                                                                             %
8233 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8234 %
8235 %  MogrifyImages() applies image processing options to a sequence of images as
8236 %  prescribed by command line options.
8237 %
8238 %  The format of the MogrifyImage method is:
8239 %
8240 %      MagickBooleanType MogrifyImages(ImageInfo *image_info,
8241 %        const MagickBooleanType post,const int argc,const char **argv,
8242 %        Image **images,Exceptioninfo *exception)
8243 %
8244 %  A description of each parameter follows:
8245 %
8246 %    o image_info: the image info..
8247 %
8248 %    o post: If true, post process image list operators otherwise pre-process.
8249 %
8250 %    o argc: Specifies a pointer to an integer describing the number of
8251 %      elements in the argument vector.
8252 %
8253 %    o argv: Specifies a pointer to a text array containing the command line
8254 %      arguments.
8255 %
8256 %    o images: pointer to a pointer of the first image in image list.
8257 %
8258 %    o exception: return any errors or warnings in this structure.
8259 %
8260 */
8261 WandExport MagickBooleanType MogrifyImages(ImageInfo *image_info,
8262   const MagickBooleanType post,const int argc,const char **argv,
8263   Image **images,ExceptionInfo *exception)
8264 {
8265 #define MogrifyImageTag  "Mogrify/Image"
8266
8267   MagickStatusType
8268     status;
8269
8270   MagickBooleanType
8271     proceed;
8272
8273   size_t
8274     n;
8275
8276   register ssize_t
8277     i;
8278
8279   assert(image_info != (ImageInfo *) NULL);
8280   assert(image_info->signature == MagickSignature);
8281   if (images == (Image **) NULL)
8282     return(MogrifyImage(image_info,argc,argv,images,exception));
8283   assert((*images)->previous == (Image *) NULL);
8284   assert((*images)->signature == MagickSignature);
8285   if ((*images)->debug != MagickFalse)
8286     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
8287       (*images)->filename);
8288   if ((argc <= 0) || (*argv == (char *) NULL))
8289     return(MagickTrue);
8290   (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
8291     (void *) NULL);
8292   status=0;
8293
8294 #if 0
8295   (void) FormatLocaleFile(stderr, "mogrify start %s %d (%s)\n",argv[0],argc,
8296     post?"post":"pre");
8297 #endif
8298
8299   /*
8300     Pre-process multi-image sequence operators
8301   */
8302   if (post == MagickFalse)
8303     status&=MogrifyImageList(image_info,argc,argv,images,exception);
8304   /*
8305     For each image, process simple single image operators
8306   */
8307   i=0;
8308   n=GetImageListLength(*images);
8309   for ( ; ; )
8310   {
8311 #if 0
8312   (void) FormatLocaleFile(stderr,"mogrify %ld of %ld\n",(long)
8313     GetImageIndexInList(*images),(long)GetImageListLength(*images));
8314 #endif
8315     status&=MogrifyImage(image_info,argc,argv,images,exception);
8316     proceed=SetImageProgress(*images,MogrifyImageTag,(MagickOffsetType) i, n);
8317     if (proceed == MagickFalse)
8318       break;
8319     if ( (*images)->next == (Image *) NULL )
8320       break;
8321     *images=(*images)->next;
8322     i++;
8323   }
8324   assert( *images != (Image *) NULL );
8325 #if 0
8326   (void) FormatLocaleFile(stderr,"mogrify end %ld of %ld\n",(long)
8327     GetImageIndexInList(*images),(long)GetImageListLength(*images));
8328 #endif
8329
8330   /*
8331     Post-process, multi-image sequence operators
8332   */
8333   *images=GetFirstImageInList(*images);
8334   if (post != MagickFalse)
8335     status&=MogrifyImageList(image_info,argc,argv,images,exception);
8336   return(status != 0 ? MagickTrue : MagickFalse);
8337 }