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