2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % CCCC OOO M M PPPP OOO SSSSS IIIII TTTTT EEEEE %
7 % C O O MM MM P P O O SS I T E %
8 % C O O M M M PPPP O O SSS I T EEE %
9 % C O O M M P O O SS I T E %
10 % CCCC OOO M M P OOO SSSSS IIIII T EEEEE %
13 % MagickWand Image Composite Methods %
20 % Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
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. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 % Use the composite program to overlap one image over another.
43 #include "MagickWand/studio.h"
44 #include "MagickWand/MagickWand.h"
45 #include "MagickWand/mogrify-private.h"
46 #include "MagickCore/string-private.h"
51 typedef struct _CompositeOptions
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 % C o m p o s i t e I m a g e C o m m a n d %
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 % CompositeImageCommand() reads one or more images and an optional mask and
89 % composites them into a new image.
91 % The format of the CompositeImageCommand method is:
93 % MagickBooleanType CompositeImageCommand(ImageInfo *image_info,int argc,
94 % char **argv,char **metadata,ExceptionInfo *exception)
96 % A description of each parameter follows:
98 % o image_info: the image info.
100 % o argc: the number of elements in the argument vector.
102 % o argv: A text array containing the command line arguments.
104 % o metadata: any metadata is returned here.
106 % o exception: return any errors or warnings in this structure.
110 static MagickBooleanType CompositeImageList(ImageInfo *image_info,Image **image,
111 Image *composite_image,CompositeOptions *composite_options,
112 ExceptionInfo *exception)
120 assert(image_info != (ImageInfo *) NULL);
121 assert(image_info->signature == MagickSignature);
122 assert(image != (Image **) NULL);
123 assert((*image)->signature == MagickSignature);
124 if ((*image)->debug != MagickFalse)
125 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
126 assert(exception != (ExceptionInfo *) NULL);
128 channel_mask=SetImageChannelMask(composite_image,composite_options->channel);
129 if (composite_image != (Image *) NULL)
131 assert(composite_image->signature == MagickSignature);
132 switch (composite_options->compose)
134 case BlendCompositeOp:
135 case BlurCompositeOp:
136 case DisplaceCompositeOp:
137 case DistortCompositeOp:
138 case DissolveCompositeOp:
139 case ModulateCompositeOp:
140 case ThresholdCompositeOp:
141 (void) SetImageArtifact(composite_image,"compose:args",
142 composite_options->compose_args);
150 if (composite_options->stegano != 0)
155 (*image)->offset=composite_options->stegano-1;
156 stegano_image=SteganoImage(*image,composite_image,exception);
157 if (stegano_image != (Image *) NULL)
159 *image=DestroyImageList(*image);
160 *image=stegano_image;
164 if (composite_options->stereo != MagickFalse)
169 stereo_image=StereoAnaglyphImage(*image,composite_image,
170 composite_options->offset.x,composite_options->offset.y,
172 if (stereo_image != (Image *) NULL)
174 *image=DestroyImageList(*image);
179 if (composite_options->tile != MagickFalse)
189 Tile the composite image.
191 (void) SetImageArtifact(composite_image,"compose:outside-overlay",
193 columns=composite_image->columns;
194 for (y=0; y < (ssize_t) (*image)->rows; y+=(ssize_t) composite_image->rows)
195 for (x=0; x < (ssize_t) (*image)->columns; x+=(ssize_t) columns)
196 status&=CompositeImage(*image,composite_image,
197 composite_options->compose,MagickTrue,x,y,exception);
205 Work out gravity Adjustment of Offset
207 SetGeometry(*image,&geometry);
208 (void) ParseAbsoluteGeometry(composite_options->geometry,
210 geometry.width=composite_image->columns;
211 geometry.height=composite_image->rows;
212 GravityAdjustGeometry((*image)->columns,(*image)->rows,
213 composite_options->gravity, &geometry);
214 (*image)->gravity=(GravityType) composite_options->gravity;
216 Digitally composite image.
218 status&=CompositeImage(*image,composite_image,
219 composite_options->compose,MagickTrue,geometry.x,geometry.y,
223 (void) SetPixelChannelMask(composite_image,channel_mask);
224 return(status != 0 ? MagickTrue : MagickFalse);
227 static MagickBooleanType CompositeUsage(void)
235 "-debug events display copious debugging information",
236 "-help print program options",
237 "-list type print a list of supported option arguments",
238 "-log format format of debugging information",
239 "-version print version information",
244 "-blend geometry blend images",
245 "-border geometry surround image with a border of color",
246 "-bordercolor color border color",
247 "-colors value preferred number of colors in the image",
248 "-decipher filename convert cipher pixels to plain pixels",
249 "-displace geometry shift lookup according to a relative displacement map",
250 "-dissolve value dissolve the two images a given percent",
251 "-distort geometry shift lookup according to a absolute distortion map",
252 "-encipher filename convert plain pixels to cipher pixels",
253 "-extract geometry extract area from image",
254 "-geometry geometry location of the composite image",
255 "-identify identify the format and characteristics of the image",
256 "-monochrome transform image to black and white",
257 "-negate replace every pixel with its complementary color ",
258 "-profile filename add ICM or IPTC information profile to image",
259 "-quantize colorspace reduce colors in this colorspace",
260 "-repage geometry size and location of an image canvas (operator)",
261 "-rotate degrees apply Paeth rotation to the image",
262 "-resize geometry resize the image",
263 "-sharpen geometry sharpen the image",
264 "-shave geometry shave pixels from the image edges",
265 "-stegano offset hide watermark within an image",
266 "-stereo geometry combine two image to create a stereo anaglyph",
267 "-strip strip image of all profiles and comments",
268 "-thumbnail geometry create a thumbnail of the image",
269 "-transform affine transform image",
270 "-type type image type",
271 "-unsharp geometry sharpen the image",
272 "-watermark geometry percent brightness and saturation of a watermark",
273 "-write filename write images to this file",
278 "-affine matrix affine transform matrix",
279 "-alpha option on, activate, off, deactivate, set, opaque, copy",
280 " transparent, extract, background, or shape",
281 "-authenticate password",
282 " decipher image with this password",
283 "-blue-primary point chromaticity blue primary point",
284 "-channel type apply option to select image channels",
285 "-colorspace type alternate image colorspace",
286 "-comment string annotate image with comment",
287 "-compose operator composite operator",
288 "-compress type type of pixel compression when writing the image",
289 "-define format:option",
290 " define one or more image format options",
291 "-depth value image depth",
292 "-density geometry horizontal and vertical density of the image",
293 "-display server get image or font from this X server",
294 "-dispose method layer disposal method",
295 "-dither method apply error diffusion to image",
296 "-encoding type text encoding type",
297 "-endian type endianness (MSB or LSB) of the image",
298 "-filter type use this filter when resizing an image",
299 "-font name render text with this font",
300 "-format \"string\" output formatted image characteristics",
301 "-gravity type which direction to gravitate towards",
302 "-green-primary point chromaticity green primary point",
303 "-interlace type type of image interlacing scheme",
304 "-interpolate method pixel color interpolation method",
305 "-label string assign a label to an image",
306 "-limit type value pixel cache resource limit",
307 "-monitor monitor progress",
308 "-page geometry size and location of an image canvas (setting)",
309 "-pointsize value font point size",
310 "-quality value JPEG/MIFF/PNG compression level",
311 "-quiet suppress all warning messages",
312 "-red-primary point chromaticity red primary point",
313 "-regard-warnings pay attention to warning messages",
314 "-respect-parentheses settings remain in effect until parenthesis boundary",
315 "-sampling-factor geometry",
316 " horizontal and vertical sampling factor",
317 "-scene value image scene number",
318 "-seed value seed a new sequence of pseudo-random numbers",
319 "-size geometry width and height of image",
320 "-synchronize synchronize image to storage device",
321 "-taint declare the image as modified",
322 "-transparent-color color",
323 " transparent color",
324 "-treedepth value color tree depth",
325 "-tile repeat composite operation across and down image",
326 "-units type the units of image resolution",
327 "-verbose print detailed information about the image",
328 "-virtual-pixel method",
329 " virtual pixel access method",
330 "-white-point point chromaticity white point",
335 "-swap indexes swap two images in the image sequence",
340 ListMagickVersion(stdout);
341 (void) printf("Usage: %s [options ...] image [options ...] composite\n"
342 " [ [options ...] mask ] [options ...] composite\n",
344 (void) printf("\nImage Settings:\n");
345 for (p=settings; *p != (char *) NULL; p++)
346 (void) printf(" %s\n",*p);
347 (void) printf("\nImage Operators:\n");
348 for (p=operators; *p != (char *) NULL; p++)
349 (void) printf(" %s\n",*p);
350 (void) printf("\nImage Stack Operators:\n");
351 for (p=stack_operators; *p != (char *) NULL; p++)
352 (void) printf(" %s\n",*p);
353 (void) printf("\nMiscellaneous Options:\n");
354 for (p=miscellaneous; *p != (char *) NULL; p++)
355 (void) printf(" %s\n",*p);
357 "\nBy default, the image format of 'file' is determined by its magic\n");
359 "number. To specify a particular image format, precede the filename\n");
361 "with an image format name and a colon (i.e. ps:image) or specify the\n");
363 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
364 (void) printf("'-' for standard input or output.\n");
368 static void GetCompositeOptions(CompositeOptions *composite_options)
370 (void) ResetMagickMemory(composite_options,0,sizeof(*composite_options));
371 composite_options->channel=DefaultChannels;
372 composite_options->compose=OverCompositeOp;
375 static void RelinquishCompositeOptions(CompositeOptions *composite_options)
377 if (composite_options->compose_args != (char *) NULL)
378 composite_options->compose_args=(char *)
379 RelinquishMagickMemory(composite_options->compose_args);
382 WandExport MagickBooleanType CompositeImageCommand(ImageInfo *image_info,
383 int argc,char **argv,char **metadata,ExceptionInfo *exception)
385 #define NotInitialized (unsigned int) (~0)
386 #define DestroyComposite() \
388 RelinquishCompositeOptions(&composite_options); \
389 DestroyImageStack(); \
390 for (i=0; i < (ssize_t) argc; i++) \
391 argv[i]=DestroyString(argv[i]); \
392 argv=(char **) RelinquishMagickMemory(argv); \
394 #define ThrowCompositeException(asperity,tag,option) \
396 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
397 option == (char *) NULL ? GetExceptionMessage(errno) : option); \
398 DestroyComposite(); \
399 return(MagickFalse); \
401 #define ThrowCompositeInvalidArgumentException(option,argument) \
403 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
404 "InvalidArgument","'%s': %s",option,argument); \
405 DestroyComposite(); \
406 return(MagickFalse); \
426 image_stack[MaxImageStackDepth+1];
446 assert(image_info != (ImageInfo *) NULL);
447 assert(image_info->signature == MagickSignature);
448 if (image_info->debug != MagickFalse)
449 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
450 assert(exception != (ExceptionInfo *) NULL);
454 if ((LocaleCompare("version",option+1) == 0) ||
455 (LocaleCompare("-version",option+1) == 0))
457 ListMagickVersion(stdout);
462 return(CompositeUsage());
463 GetCompositeOptions(&composite_options);
464 filename=(char *) NULL;
469 option=(char *) NULL;
471 respect_parenthesis=MagickFalse;
474 Check command syntax.
476 composite_image=NewImageList();
477 image=NewImageList();
478 mask_image=NewImageList();
479 ReadCommandlLine(argc,&argv);
480 status=ExpandFilenames(&argc,&argv);
481 if (status == MagickFalse)
482 ThrowCompositeException(ResourceLimitError,"MemoryAllocationFailed",
483 GetExceptionMessage(errno));
484 for (i=1; i < (ssize_t) (argc-1); i++)
487 if (LocaleCompare(option,"(") == 0)
489 FireImageStack(MagickFalse,MagickTrue,pend);
490 if (k == MaxImageStackDepth)
491 ThrowCompositeException(OptionError,"ParenthesisNestedTooDeeply",
496 if (LocaleCompare(option,")") == 0)
498 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
500 ThrowCompositeException(OptionError,"UnableToParseExpression",option);
504 if (IsCommandOption(option) == MagickFalse)
512 FireImageStack(MagickFalse,MagickFalse,pend);
514 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
516 images=ReadImages(image_info,filename,exception);
517 status&=(images != (Image *) NULL) &&
518 (exception->severity < ErrorException);
519 if (images == (Image *) NULL)
521 AppendImageStack(images);
524 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
529 if (LocaleCompare("affine",option+1) == 0)
534 if (i == (ssize_t) argc)
535 ThrowCompositeException(OptionError,"MissingArgument",option);
536 if (IsGeometry(argv[i]) == MagickFalse)
537 ThrowCompositeInvalidArgumentException(option,argv[i]);
540 if (LocaleCompare("alpha",option+1) == 0)
548 if (i == (ssize_t) argc)
549 ThrowCompositeException(OptionError,"MissingArgument",option);
550 type=ParseCommandOption(MagickAlphaChannelOptions,MagickFalse,argv[i]);
552 ThrowCompositeException(OptionError,
553 "UnrecognizedAlphaChannelOption",argv[i]);
556 if (LocaleCompare("authenticate",option+1) == 0)
561 if (i == (ssize_t) argc)
562 ThrowCompositeException(OptionError,"MissingArgument",option);
565 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
569 if (LocaleCompare("background",option+1) == 0)
574 if (i == (ssize_t) argc)
575 ThrowCompositeException(OptionError,"MissingArgument",option);
578 if (LocaleCompare("blend",option+1) == 0)
580 (void) CloneString(&composite_options.compose_args,(char *) NULL);
584 if (i == (ssize_t) argc)
585 ThrowCompositeException(OptionError,"MissingArgument",option);
586 if (IsGeometry(argv[i]) == MagickFalse)
587 ThrowCompositeInvalidArgumentException(option,argv[i]);
588 (void) CloneString(&composite_options.compose_args,argv[i]);
589 composite_options.compose=BlendCompositeOp;
592 if (LocaleCompare("blur",option+1) == 0)
594 (void) CloneString(&composite_options.compose_args,(char *) NULL);
598 if (i == (ssize_t) argc)
599 ThrowCompositeException(OptionError,"MissingArgument",option);
600 if (IsGeometry(argv[i]) == MagickFalse)
601 ThrowCompositeInvalidArgumentException(option,argv[i]);
602 (void) CloneString(&composite_options.compose_args,argv[i]);
603 composite_options.compose=BlurCompositeOp;
606 if (LocaleCompare("blue-primary",option+1) == 0)
611 if (i == (ssize_t) argc)
612 ThrowCompositeException(OptionError,"MissingArgument",option);
613 if (IsGeometry(argv[i]) == MagickFalse)
614 ThrowCompositeInvalidArgumentException(option,argv[i]);
617 if (LocaleCompare("border",option+1) == 0)
622 if (i == (ssize_t) (argc-1))
623 ThrowCompositeException(OptionError,"MissingArgument",option);
624 if (IsGeometry(argv[i]) == MagickFalse)
625 ThrowCompositeInvalidArgumentException(option,argv[i]);
628 if (LocaleCompare("bordercolor",option+1) == 0)
633 if (i == (ssize_t) (argc-1))
634 ThrowCompositeException(OptionError,"MissingArgument",option);
637 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
641 if (LocaleCompare("cache",option+1) == 0)
646 if (i == (ssize_t) argc)
647 ThrowCompositeException(OptionError,"MissingArgument",option);
648 if (IsGeometry(argv[i]) == MagickFalse)
649 ThrowCompositeInvalidArgumentException(option,argv[i]);
652 if (LocaleCompare("channel",option+1) == 0)
659 composite_options.channel=DefaultChannels;
663 if (i == (ssize_t) (argc-1))
664 ThrowCompositeException(OptionError,"MissingArgument",option);
665 channel=ParseChannelOption(argv[i]);
667 ThrowCompositeException(OptionError,"UnrecognizedChannelType",
669 composite_options.channel=(ChannelType) channel;
672 if (LocaleCompare("colors",option+1) == 0)
677 if (i == (ssize_t) argc)
678 ThrowCompositeException(OptionError,"MissingArgument",option);
679 if (IsGeometry(argv[i]) == MagickFalse)
680 ThrowCompositeInvalidArgumentException(option,argv[i]);
683 if (LocaleCompare("colorspace",option+1) == 0)
691 if (i == (ssize_t) argc)
692 ThrowCompositeException(OptionError,"MissingArgument",option);
693 colorspace=ParseCommandOption(MagickColorspaceOptions,
694 MagickFalse,argv[i]);
696 ThrowCompositeException(OptionError,"UnrecognizedColorspace",
700 if (LocaleCompare("comment",option+1) == 0)
705 if (i == (ssize_t) argc)
706 ThrowCompositeException(OptionError,"MissingArgument",option);
709 if (LocaleCompare("compose",option+1) == 0)
714 composite_options.compose=UndefinedCompositeOp;
718 if (i == (ssize_t) argc)
719 ThrowCompositeException(OptionError,"MissingArgument",option);
720 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,
723 ThrowCompositeException(OptionError,"UnrecognizedComposeOperator",
725 composite_options.compose=(CompositeOperator) compose;
728 if (LocaleCompare("compress",option+1) == 0)
736 if (i == (ssize_t) argc)
737 ThrowCompositeException(OptionError,"MissingArgument",option);
738 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
741 ThrowCompositeException(OptionError,
742 "UnrecognizedImageCompression",argv[i]);
745 if (LocaleCompare("concurrent",option+1) == 0)
747 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
751 if (LocaleCompare("debug",option+1) == 0)
759 if (i == (ssize_t) argc)
760 ThrowCompositeException(OptionError,"MissingArgument",option);
761 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
763 ThrowCompositeException(OptionError,"UnrecognizedEventType",
765 (void) SetLogEventMask(argv[i]);
768 if (LocaleCompare("decipher",option+1) == 0)
773 if (i == (ssize_t) (argc-1))
774 ThrowCompositeException(OptionError,"MissingArgument",option);
777 if (LocaleCompare("define",option+1) == 0)
780 if (i == (ssize_t) argc)
781 ThrowCompositeException(OptionError,"MissingArgument",option);
787 define=GetImageOption(image_info,argv[i]);
788 if (define == (const char *) NULL)
789 ThrowCompositeException(OptionError,"NoSuchOption",argv[i]);
794 if (LocaleCompare("density",option+1) == 0)
799 if (i == (ssize_t) argc)
800 ThrowCompositeException(OptionError,"MissingArgument",option);
801 if (IsGeometry(argv[i]) == MagickFalse)
802 ThrowCompositeInvalidArgumentException(option,argv[i]);
805 if (LocaleCompare("depth",option+1) == 0)
810 if (i == (ssize_t) argc)
811 ThrowCompositeException(OptionError,"MissingArgument",option);
812 if (IsGeometry(argv[i]) == MagickFalse)
813 ThrowCompositeInvalidArgumentException(option,argv[i]);
816 if (LocaleCompare("displace",option+1) == 0)
818 (void) CloneString(&composite_options.compose_args,(char *) NULL);
822 if (i == (ssize_t) argc)
823 ThrowCompositeException(OptionError,"MissingArgument",option);
824 if (IsGeometry(argv[i]) == MagickFalse)
825 ThrowCompositeInvalidArgumentException(option,argv[i]);
826 (void) CloneString(&composite_options.compose_args,argv[i]);
827 composite_options.compose=DisplaceCompositeOp;
830 if (LocaleCompare("display",option+1) == 0)
835 if (i == (ssize_t) argc)
836 ThrowCompositeException(OptionError,"MissingArgument",option);
839 if (LocaleCompare("dispose",option+1) == 0)
847 if (i == (ssize_t) argc)
848 ThrowCompositeException(OptionError,"MissingArgument",option);
849 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
851 ThrowCompositeException(OptionError,"UnrecognizedDisposeMethod",
855 if (LocaleCompare("dissolve",option+1) == 0)
857 (void) CloneString(&composite_options.compose_args,(char *) NULL);
861 if (i == (ssize_t) argc)
862 ThrowCompositeException(OptionError,"MissingArgument",option);
863 if (IsGeometry(argv[i]) == MagickFalse)
864 ThrowCompositeInvalidArgumentException(option,argv[i]);
865 (void) CloneString(&composite_options.compose_args,argv[i]);
866 composite_options.compose=DissolveCompositeOp;
869 if (LocaleCompare("distort",option+1) == 0)
871 (void) CloneString(&composite_options.compose_args,(char *) NULL);
875 if (i == (ssize_t) argc)
876 ThrowCompositeException(OptionError,"MissingArgument",option);
877 if (IsGeometry(argv[i]) == MagickFalse)
878 ThrowCompositeInvalidArgumentException(option,argv[i]);
879 (void) CloneString(&composite_options.compose_args,argv[i]);
880 composite_options.compose=DistortCompositeOp;
883 if (LocaleCompare("dither",option+1) == 0)
891 if (i == (ssize_t) argc)
892 ThrowCompositeException(OptionError,"MissingArgument",option);
893 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
895 ThrowCompositeException(OptionError,"UnrecognizedDitherMethod",
899 if (LocaleCompare("duration",option+1) == 0)
904 if (i == (ssize_t) (argc-1))
905 ThrowCompositeException(OptionError,"MissingArgument",option);
906 if (IsGeometry(argv[i]) == MagickFalse)
907 ThrowCompositeInvalidArgumentException(option,argv[i]);
910 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
914 if (LocaleCompare("encipher",option+1) == 0)
919 if (i == (ssize_t) (argc-1))
920 ThrowCompositeException(OptionError,"MissingArgument",option);
923 if (LocaleCompare("encoding",option+1) == 0)
928 if (i == (ssize_t) argc)
929 ThrowCompositeException(OptionError,"MissingArgument",option);
932 if (LocaleCompare("endian",option+1) == 0)
940 if (i == (ssize_t) argc)
941 ThrowCompositeException(OptionError,"MissingArgument",option);
942 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,
945 ThrowCompositeException(OptionError,"UnrecognizedEndianType",
949 if (LocaleCompare("extract",option+1) == 0)
954 if (i == (ssize_t) argc)
955 ThrowCompositeException(OptionError,"MissingArgument",option);
956 if (IsGeometry(argv[i]) == MagickFalse)
957 ThrowCompositeInvalidArgumentException(option,argv[i]);
960 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
964 if (LocaleCompare("filter",option+1) == 0)
972 if (i == (ssize_t) argc)
973 ThrowCompositeException(OptionError,"MissingArgument",option);
974 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
976 ThrowCompositeException(OptionError,"UnrecognizedImageFilter",
980 if (LocaleCompare("font",option+1) == 0)
985 if (i == (ssize_t) argc)
986 ThrowCompositeException(OptionError,"MissingArgument",option);
989 if (LocaleCompare("format",option+1) == 0)
994 if (i == (ssize_t) argc)
995 ThrowCompositeException(OptionError,"MissingArgument",option);
999 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1003 if (LocaleCompare("geometry",option+1) == 0)
1005 (void) CloneString(&composite_options.geometry,(char *) NULL);
1009 if (i == (ssize_t) argc)
1010 ThrowCompositeException(OptionError,"MissingArgument",option);
1011 if (IsGeometry(argv[i]) == MagickFalse)
1012 ThrowCompositeInvalidArgumentException(option,argv[i]);
1013 (void) CloneString(&composite_options.geometry,argv[i]);
1016 if (LocaleCompare("gravity",option+1) == 0)
1021 composite_options.gravity=UndefinedGravity;
1025 if (i == (ssize_t) argc)
1026 ThrowCompositeException(OptionError,"MissingArgument",option);
1027 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,
1030 ThrowCompositeException(OptionError,"UnrecognizedGravityType",
1032 composite_options.gravity=(GravityType) gravity;
1035 if (LocaleCompare("green-primary",option+1) == 0)
1040 if (i == (ssize_t) argc)
1041 ThrowCompositeException(OptionError,"MissingArgument",option);
1042 if (IsGeometry(argv[i]) == MagickFalse)
1043 ThrowCompositeInvalidArgumentException(option,argv[i]);
1046 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1050 if ((LocaleCompare("help",option+1) == 0) ||
1051 (LocaleCompare("-help",option+1) == 0))
1052 return(CompositeUsage());
1053 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1057 if (LocaleCompare("identify",option+1) == 0)
1059 if (LocaleCompare("interlace",option+1) == 0)
1067 if (i == (ssize_t) argc)
1068 ThrowCompositeException(OptionError,"MissingArgument",option);
1069 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
1072 ThrowCompositeException(OptionError,
1073 "UnrecognizedInterlaceType",argv[i]);
1076 if (LocaleCompare("interpolate",option+1) == 0)
1084 if (i == (ssize_t) argc)
1085 ThrowCompositeException(OptionError,"MissingArgument",option);
1086 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
1088 if (interpolate < 0)
1089 ThrowCompositeException(OptionError,
1090 "UnrecognizedInterpolateMethod",argv[i]);
1093 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1097 if (LocaleCompare("label",option+1) == 0)
1102 if (i == (ssize_t) argc)
1103 ThrowCompositeException(OptionError,"MissingArgument",option);
1106 if (LocaleCompare("limit",option+1) == 0)
1120 if (i == (ssize_t) argc)
1121 ThrowCompositeException(OptionError,"MissingArgument",option);
1122 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
1125 ThrowCompositeException(OptionError,"UnrecognizedResourceType",
1128 if (i == (ssize_t) argc)
1129 ThrowCompositeException(OptionError,"MissingArgument",option);
1130 value=StringToDouble(argv[i],&p);
1132 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
1133 ThrowCompositeInvalidArgumentException(option,argv[i]);
1136 if (LocaleCompare("list",option+1) == 0)
1144 if (i == (ssize_t) argc)
1145 ThrowCompositeException(OptionError,"MissingArgument",option);
1146 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
1148 ThrowCompositeException(OptionError,"UnrecognizedListType",
1150 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
1153 return(status != 0 ? MagickFalse : MagickTrue);
1155 if (LocaleCompare("log",option+1) == 0)
1160 if ((i == (ssize_t) argc) || (strchr(argv[i],'%') == (char *) NULL))
1161 ThrowCompositeException(OptionError,"MissingArgument",option);
1164 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1168 if (LocaleCompare("matte",option+1) == 0)
1170 if (LocaleCompare("monitor",option+1) == 0)
1172 if (LocaleCompare("monochrome",option+1) == 0)
1174 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1178 if (LocaleCompare("negate",option+1) == 0)
1180 if (LocaleCompare("noop",option+1) == 0)
1182 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1186 if (LocaleCompare("page",option+1) == 0)
1191 if (i == (ssize_t) argc)
1192 ThrowCompositeException(OptionError,"MissingArgument",option);
1195 if (LocaleCompare("pointsize",option+1) == 0)
1200 if (i == (ssize_t) (argc-1))
1201 ThrowCompositeException(OptionError,"MissingArgument",option);
1202 if (IsGeometry(argv[i]) == MagickFalse)
1203 ThrowCompositeInvalidArgumentException(option,argv[i]);
1206 if (LocaleCompare("process",option+1) == 0)
1211 if (i == (ssize_t) argc)
1212 ThrowCompositeException(OptionError,"MissingArgument",option);
1215 if (LocaleCompare("profile",option+1) == 0)
1218 if (i == (ssize_t) argc)
1219 ThrowCompositeException(OptionError,"MissingArgument",option);
1222 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1226 if (LocaleCompare("quality",option+1) == 0)
1231 if (i == (ssize_t) argc)
1232 ThrowCompositeException(OptionError,"MissingArgument",option);
1233 if (IsGeometry(argv[i]) == MagickFalse)
1234 ThrowCompositeInvalidArgumentException(option,argv[i]);
1237 if (LocaleCompare("quantize",option+1) == 0)
1245 if (i == (ssize_t) (argc-1))
1246 ThrowCompositeException(OptionError,"MissingArgument",option);
1247 colorspace=ParseCommandOption(MagickColorspaceOptions,
1248 MagickFalse,argv[i]);
1250 ThrowCompositeException(OptionError,"UnrecognizedColorspace",
1254 if (LocaleCompare("quiet",option+1) == 0)
1256 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1260 if (LocaleCompare("red-primary",option+1) == 0)
1265 if (i == (ssize_t) argc)
1266 ThrowCompositeException(OptionError,"MissingArgument",option);
1267 if (IsGeometry(argv[i]) == MagickFalse)
1268 ThrowCompositeInvalidArgumentException(option,argv[i]);
1271 if (LocaleCompare("regard-warnings",option+1) == 0)
1273 if (LocaleCompare("render",option+1) == 0)
1275 if (LocaleCompare("repage",option+1) == 0)
1280 if (i == (ssize_t) argc)
1281 ThrowCompositeException(OptionError,"MissingArgument",option);
1282 if (IsGeometry(argv[i]) == MagickFalse)
1283 ThrowCompositeInvalidArgumentException(option,argv[i]);
1286 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
1288 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
1291 if (LocaleCompare("resize",option+1) == 0)
1296 if (i == (ssize_t) argc)
1297 ThrowCompositeException(OptionError,"MissingArgument",option);
1298 if (IsGeometry(argv[i]) == MagickFalse)
1299 ThrowCompositeInvalidArgumentException(option,argv[i]);
1302 if (LocaleCompare("rotate",option+1) == 0)
1305 if (i == (ssize_t) argc)
1306 ThrowCompositeException(OptionError,"MissingArgument",option);
1307 if (IsGeometry(argv[i]) == MagickFalse)
1308 ThrowCompositeInvalidArgumentException(option,argv[i]);
1311 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1315 if (LocaleCompare("sampling-factor",option+1) == 0)
1320 if (i == (ssize_t) argc)
1321 ThrowCompositeException(OptionError,"MissingArgument",option);
1322 if (IsGeometry(argv[i]) == MagickFalse)
1323 ThrowCompositeInvalidArgumentException(option,argv[i]);
1326 if (LocaleCompare("scene",option+1) == 0)
1331 if (i == (ssize_t) argc)
1332 ThrowCompositeException(OptionError,"MissingArgument",option);
1333 if (IsGeometry(argv[i]) == MagickFalse)
1334 ThrowCompositeInvalidArgumentException(option,argv[i]);
1337 if (LocaleCompare("seed",option+1) == 0)
1342 if (i == (ssize_t) (argc-1))
1343 ThrowCompositeException(OptionError,"MissingArgument",option);
1344 if (IsGeometry(argv[i]) == MagickFalse)
1345 ThrowCompositeInvalidArgumentException(option,argv[i]);
1348 if (LocaleCompare("sharpen",option+1) == 0)
1351 if (i == (ssize_t) argc)
1352 ThrowCompositeException(OptionError,"MissingArgument",option);
1353 if (IsGeometry(argv[i]) == MagickFalse)
1354 ThrowCompositeInvalidArgumentException(option,argv[i]);
1357 if (LocaleCompare("shave",option+1) == 0)
1362 if (i == (ssize_t) (argc-1))
1363 ThrowCompositeException(OptionError,"MissingArgument",option);
1364 if (IsGeometry(argv[i]) == MagickFalse)
1365 ThrowCompositeInvalidArgumentException(option,argv[i]);
1368 if (LocaleCompare("size",option+1) == 0)
1373 if (i == (ssize_t) argc)
1374 ThrowCompositeException(OptionError,"MissingArgument",option);
1375 if (IsGeometry(argv[i]) == MagickFalse)
1376 ThrowCompositeInvalidArgumentException(option,argv[i]);
1379 if (LocaleCompare("stegano",option+1) == 0)
1381 composite_options.stegano=0;
1385 if (i == (ssize_t) argc)
1386 ThrowCompositeException(OptionError,"MissingArgument",option);
1387 if (IsGeometry(argv[i]) == MagickFalse)
1388 ThrowCompositeInvalidArgumentException(option,argv[i]);
1389 composite_options.stegano=(ssize_t) StringToLong(argv[i])+1;
1392 if (LocaleCompare("stereo",option+1) == 0)
1397 composite_options.stereo=MagickFalse;
1401 if (i == (ssize_t) argc)
1402 ThrowCompositeException(OptionError,"MissingArgument",option);
1403 if (IsGeometry(argv[i]) == MagickFalse)
1404 ThrowCompositeInvalidArgumentException(option,argv[i]);
1405 flags=ParseAbsoluteGeometry(argv[i],&composite_options.offset);
1406 if ((flags & YValue) == 0)
1407 composite_options.offset.y=composite_options.offset.x;
1408 composite_options.stereo=MagickTrue;
1411 if (LocaleCompare("strip",option+1) == 0)
1413 if (LocaleCompare("support",option+1) == 0)
1415 i++; /* deprecated */
1418 if (LocaleCompare("swap",option+1) == 0)
1423 if (i == (ssize_t) (argc-1))
1424 ThrowCompositeException(OptionError,"MissingArgument",option);
1425 if (IsGeometry(argv[i]) == MagickFalse)
1426 ThrowCompositeInvalidArgumentException(option,argv[i]);
1429 if (LocaleCompare("synchronize",option+1) == 0)
1431 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1435 if (LocaleCompare("taint",option+1) == 0)
1437 if (LocaleCompare("thumbnail",option+1) == 0)
1442 if (i == (ssize_t) argc)
1443 ThrowCompositeException(OptionError,"MissingArgument",option);
1444 if (IsGeometry(argv[i]) == MagickFalse)
1445 ThrowCompositeInvalidArgumentException(option,argv[i]);
1448 if (LocaleCompare("tile",option+1) == 0)
1450 composite_options.tile=(*option == '-') ? MagickTrue : MagickFalse;
1451 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
1454 if (LocaleCompare("transform",option+1) == 0)
1456 if (LocaleCompare("transparent-color",option+1) == 0)
1461 if (i == (ssize_t) (argc-1))
1462 ThrowCompositeException(OptionError,"MissingArgument",option);
1465 if (LocaleCompare("treedepth",option+1) == 0)
1470 if (i == (ssize_t) argc)
1471 ThrowCompositeException(OptionError,"MissingArgument",option);
1472 if (IsGeometry(argv[i]) == MagickFalse)
1473 ThrowCompositeInvalidArgumentException(option,argv[i]);
1476 if (LocaleCompare("type",option+1) == 0)
1484 if (i == (ssize_t) argc)
1485 ThrowCompositeException(OptionError,"MissingArgument",option);
1486 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
1488 ThrowCompositeException(OptionError,"UnrecognizedImageType",
1492 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1496 if (LocaleCompare("units",option+1) == 0)
1504 if (i == (ssize_t) argc)
1505 ThrowCompositeException(OptionError,"MissingArgument",option);
1506 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
1509 ThrowCompositeException(OptionError,"UnrecognizedUnitsType",
1513 if (LocaleCompare("unsharp",option+1) == 0)
1515 (void) CloneString(&composite_options.compose_args,(char *) NULL);
1519 if (i == (ssize_t) argc)
1520 ThrowCompositeException(OptionError,"MissingArgument",option);
1521 if (IsGeometry(argv[i]) == MagickFalse)
1522 ThrowCompositeInvalidArgumentException(option,argv[i]);
1523 (void) CloneString(&composite_options.compose_args,argv[i]);
1524 composite_options.compose=ThresholdCompositeOp;
1527 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1531 if (LocaleCompare("verbose",option+1) == 0)
1533 if ((LocaleCompare("version",option+1) == 0) ||
1534 (LocaleCompare("-version",option+1) == 0))
1536 ListMagickVersion(stdout);
1539 if (LocaleCompare("virtual-pixel",option+1) == 0)
1547 if (i == (ssize_t) argc)
1548 ThrowCompositeException(OptionError,"MissingArgument",option);
1549 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
1552 ThrowCompositeException(OptionError,
1553 "UnrecognizedVirtualPixelMethod",argv[i]);
1556 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1560 if (LocaleCompare("watermark",option+1) == 0)
1562 (void) CloneString(&composite_options.compose_args,(char *) NULL);
1566 if (i == (ssize_t) argc)
1567 ThrowCompositeException(OptionError,"MissingArgument",option);
1568 if (IsGeometry(argv[i]) == MagickFalse)
1569 ThrowCompositeInvalidArgumentException(option,argv[i]);
1570 (void) CloneString(&composite_options.compose_args,argv[i]);
1571 composite_options.compose=ModulateCompositeOp;
1574 if (LocaleCompare("white-point",option+1) == 0)
1579 if (i == (ssize_t) argc)
1580 ThrowCompositeException(OptionError,"MissingArgument",option);
1581 if (IsGeometry(argv[i]) == MagickFalse)
1582 ThrowCompositeInvalidArgumentException(option,argv[i]);
1585 if (LocaleCompare("write",option+1) == 0)
1588 if (i == (ssize_t) argc)
1589 ThrowCompositeException(OptionError,"MissingArgument",option);
1592 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1597 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1599 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
1600 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
1601 if (fire != MagickFalse)
1602 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
1605 ThrowCompositeException(OptionError,"UnbalancedParenthesis",argv[i]);
1606 if (i-- != (ssize_t) (argc-1))
1607 ThrowCompositeException(OptionError,"MissingAnImageFilename",argv[i]);
1608 if ((image == (Image *) NULL) || (GetImageListLength(image) < 2))
1609 ThrowCompositeException(OptionError,"MissingAnImageFilename",argv[argc-1]);
1610 FinalizeImageSettings(image_info,image,MagickTrue);
1611 if ((image == (Image *) NULL) || (GetImageListLength(image) < 2))
1612 ThrowCompositeException(OptionError,"MissingAnImageFilename",argv[argc-1]);
1616 RemoveImageStack(composite_image);
1617 RemoveImageStack(images);
1618 (void) TransformImage(&composite_image,(char *) NULL,
1619 composite_image->geometry,exception);
1620 RemoveImageStack(mask_image);
1621 if (mask_image != (Image *) NULL)
1623 if ((composite_options.compose == DisplaceCompositeOp) ||
1624 (composite_options.compose == DistortCompositeOp))
1625 status&=CompositeImage(composite_image,mask_image,
1626 CopyGreenCompositeOp,MagickTrue,0,0,exception);
1628 status&=CompositeImage(composite_image,mask_image,IntensityCompositeOp,
1629 MagickTrue,0,0,exception);
1630 mask_image=DestroyImage(mask_image);
1632 status&=CompositeImageList(image_info,&images,composite_image,
1633 &composite_options,exception);
1634 composite_image=DestroyImage(composite_image);
1636 Write composite images.
1638 status&=WriteImages(image_info,images,argv[argc-1],exception);
1639 if (metadata != (char **) NULL)
1644 text=InterpretImageProperties(image_info,images,format,exception);
1645 if (text == (char *) NULL)
1646 ThrowCompositeException(ResourceLimitError,"MemoryAllocationFailed",
1647 GetExceptionMessage(errno));
1648 (void) ConcatenateString(&(*metadata),text);
1649 (void) ConcatenateString(&(*metadata),"\n");
1650 text=DestroyString(text);
1652 images=DestroyImage(images);
1653 RelinquishCompositeOptions(&composite_options);
1655 return(status != 0 ? MagickTrue : MagickFalse);