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