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