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