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