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