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 "-matte store matte channel if the image has one",
308 "-monitor monitor progress",
309 "-page geometry size and location of an image canvas (setting)",
310 "-pointsize value font point size",
311 "-quality value JPEG/MIFF/PNG compression level",
312 "-quiet suppress all warning messages",
313 "-red-primary point chromaticity red primary point",
314 "-regard-warnings pay attention to warning messages",
315 "-respect-parentheses settings remain in effect until parenthesis boundary",
316 "-sampling-factor geometry",
317 " horizontal and vertical sampling factor",
318 "-scene value image scene number",
319 "-seed value seed a new sequence of pseudo-random numbers",
320 "-size geometry width and height of image",
321 "-support factor resize support: > 1.0 is blurry, < 1.0 is sharp",
322 "-synchronize synchronize image to storage device",
323 "-taint declare the image as modified",
324 "-transparent-color color",
325 " transparent color",
326 "-treedepth value color tree depth",
327 "-tile repeat composite operation across and down image",
328 "-units type the units of image resolution",
329 "-verbose print detailed information about the image",
330 "-virtual-pixel method",
331 " virtual pixel access method",
332 "-white-point point chromaticity white point",
337 "-swap indexes swap two images in the image sequence",
342 ListMagickVersion(stdout);
343 (void) printf("Usage: %s [options ...] image [options ...] composite\n"
344 " [ [options ...] mask ] [options ...] composite\n",
346 (void) printf("\nImage Settings:\n");
347 for (p=settings; *p != (char *) NULL; p++)
348 (void) printf(" %s\n",*p);
349 (void) printf("\nImage Operators:\n");
350 for (p=operators; *p != (char *) NULL; p++)
351 (void) printf(" %s\n",*p);
352 (void) printf("\nImage Stack Operators:\n");
353 for (p=stack_operators; *p != (char *) NULL; p++)
354 (void) printf(" %s\n",*p);
355 (void) printf("\nMiscellaneous Options:\n");
356 for (p=miscellaneous; *p != (char *) NULL; p++)
357 (void) printf(" %s\n",*p);
359 "\nBy default, the image format of 'file' is determined by its magic\n");
361 "number. To specify a particular image format, precede the filename\n");
363 "with an image format name and a colon (i.e. ps:image) or specify the\n");
365 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
366 (void) printf("'-' for standard input or output.\n");
370 static void GetCompositeOptions(CompositeOptions *composite_options)
372 (void) ResetMagickMemory(composite_options,0,sizeof(*composite_options));
373 composite_options->channel=DefaultChannels;
374 composite_options->compose=OverCompositeOp;
377 static void RelinquishCompositeOptions(CompositeOptions *composite_options)
379 if (composite_options->compose_args != (char *) NULL)
380 composite_options->compose_args=(char *)
381 RelinquishMagickMemory(composite_options->compose_args);
384 WandExport MagickBooleanType CompositeImageCommand(ImageInfo *image_info,
385 int argc,char **argv,char **metadata,ExceptionInfo *exception)
387 #define NotInitialized (unsigned int) (~0)
388 #define DestroyComposite() \
390 RelinquishCompositeOptions(&composite_options); \
391 DestroyImageStack(); \
392 for (i=0; i < (ssize_t) argc; i++) \
393 argv[i]=DestroyString(argv[i]); \
394 argv=(char **) RelinquishMagickMemory(argv); \
396 #define ThrowCompositeException(asperity,tag,option) \
398 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
399 option == (char *) NULL ? GetExceptionMessage(errno) : option); \
400 DestroyComposite(); \
401 return(MagickFalse); \
403 #define ThrowCompositeInvalidArgumentException(option,argument) \
405 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
406 "InvalidArgument","'%s': %s",option,argument); \
407 DestroyComposite(); \
408 return(MagickFalse); \
428 image_stack[MaxImageStackDepth+1];
448 assert(image_info != (ImageInfo *) NULL);
449 assert(image_info->signature == MagickSignature);
450 if (image_info->debug != MagickFalse)
451 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
452 assert(exception != (ExceptionInfo *) NULL);
456 if ((LocaleCompare("version",option+1) == 0) ||
457 (LocaleCompare("-version",option+1) == 0))
459 ListMagickVersion(stdout);
464 return(CompositeUsage());
465 GetCompositeOptions(&composite_options);
466 filename=(char *) NULL;
471 option=(char *) NULL;
473 respect_parenthesis=MagickFalse;
476 Check command syntax.
478 composite_image=NewImageList();
479 image=NewImageList();
480 mask_image=NewImageList();
481 ReadCommandlLine(argc,&argv);
482 status=ExpandFilenames(&argc,&argv);
483 if (status == MagickFalse)
484 ThrowCompositeException(ResourceLimitError,"MemoryAllocationFailed",
485 GetExceptionMessage(errno));
486 for (i=1; i < (ssize_t) (argc-1); i++)
489 if (LocaleCompare(option,"(") == 0)
491 FireImageStack(MagickFalse,MagickTrue,pend);
492 if (k == MaxImageStackDepth)
493 ThrowCompositeException(OptionError,"ParenthesisNestedTooDeeply",
498 if (LocaleCompare(option,")") == 0)
500 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
502 ThrowCompositeException(OptionError,"UnableToParseExpression",option);
506 if (IsCommandOption(option) == MagickFalse)
514 FireImageStack(MagickFalse,MagickFalse,pend);
516 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
518 images=ReadImages(image_info,filename,exception);
519 status&=(images != (Image *) NULL) &&
520 (exception->severity < ErrorException);
521 if (images == (Image *) NULL)
523 AppendImageStack(images);
526 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
531 if (LocaleCompare("affine",option+1) == 0)
536 if (i == (ssize_t) argc)
537 ThrowCompositeException(OptionError,"MissingArgument",option);
538 if (IsGeometry(argv[i]) == MagickFalse)
539 ThrowCompositeInvalidArgumentException(option,argv[i]);
542 if (LocaleCompare("alpha",option+1) == 0)
550 if (i == (ssize_t) argc)
551 ThrowCompositeException(OptionError,"MissingArgument",option);
552 type=ParseCommandOption(MagickAlphaChannelOptions,MagickFalse,argv[i]);
554 ThrowCompositeException(OptionError,
555 "UnrecognizedAlphaChannelOption",argv[i]);
558 if (LocaleCompare("authenticate",option+1) == 0)
563 if (i == (ssize_t) argc)
564 ThrowCompositeException(OptionError,"MissingArgument",option);
567 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
571 if (LocaleCompare("background",option+1) == 0)
576 if (i == (ssize_t) argc)
577 ThrowCompositeException(OptionError,"MissingArgument",option);
580 if (LocaleCompare("blend",option+1) == 0)
582 (void) CloneString(&composite_options.compose_args,(char *) NULL);
586 if (i == (ssize_t) argc)
587 ThrowCompositeException(OptionError,"MissingArgument",option);
588 if (IsGeometry(argv[i]) == MagickFalse)
589 ThrowCompositeInvalidArgumentException(option,argv[i]);
590 (void) CloneString(&composite_options.compose_args,argv[i]);
591 composite_options.compose=BlendCompositeOp;
594 if (LocaleCompare("blur",option+1) == 0)
596 (void) CloneString(&composite_options.compose_args,(char *) NULL);
600 if (i == (ssize_t) argc)
601 ThrowCompositeException(OptionError,"MissingArgument",option);
602 if (IsGeometry(argv[i]) == MagickFalse)
603 ThrowCompositeInvalidArgumentException(option,argv[i]);
604 (void) CloneString(&composite_options.compose_args,argv[i]);
605 composite_options.compose=BlurCompositeOp;
608 if (LocaleCompare("blue-primary",option+1) == 0)
613 if (i == (ssize_t) argc)
614 ThrowCompositeException(OptionError,"MissingArgument",option);
615 if (IsGeometry(argv[i]) == MagickFalse)
616 ThrowCompositeInvalidArgumentException(option,argv[i]);
619 if (LocaleCompare("border",option+1) == 0)
624 if (i == (ssize_t) (argc-1))
625 ThrowCompositeException(OptionError,"MissingArgument",option);
626 if (IsGeometry(argv[i]) == MagickFalse)
627 ThrowCompositeInvalidArgumentException(option,argv[i]);
630 if (LocaleCompare("bordercolor",option+1) == 0)
635 if (i == (ssize_t) (argc-1))
636 ThrowCompositeException(OptionError,"MissingArgument",option);
639 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
643 if (LocaleCompare("cache",option+1) == 0)
648 if (i == (ssize_t) argc)
649 ThrowCompositeException(OptionError,"MissingArgument",option);
650 if (IsGeometry(argv[i]) == MagickFalse)
651 ThrowCompositeInvalidArgumentException(option,argv[i]);
654 if (LocaleCompare("channel",option+1) == 0)
661 composite_options.channel=DefaultChannels;
665 if (i == (ssize_t) (argc-1))
666 ThrowCompositeException(OptionError,"MissingArgument",option);
667 channel=ParseChannelOption(argv[i]);
669 ThrowCompositeException(OptionError,"UnrecognizedChannelType",
671 composite_options.channel=(ChannelType) channel;
674 if (LocaleCompare("colors",option+1) == 0)
679 if (i == (ssize_t) argc)
680 ThrowCompositeException(OptionError,"MissingArgument",option);
681 if (IsGeometry(argv[i]) == MagickFalse)
682 ThrowCompositeInvalidArgumentException(option,argv[i]);
685 if (LocaleCompare("colorspace",option+1) == 0)
693 if (i == (ssize_t) argc)
694 ThrowCompositeException(OptionError,"MissingArgument",option);
695 colorspace=ParseCommandOption(MagickColorspaceOptions,
696 MagickFalse,argv[i]);
698 ThrowCompositeException(OptionError,"UnrecognizedColorspace",
702 if (LocaleCompare("comment",option+1) == 0)
707 if (i == (ssize_t) argc)
708 ThrowCompositeException(OptionError,"MissingArgument",option);
711 if (LocaleCompare("compose",option+1) == 0)
716 composite_options.compose=UndefinedCompositeOp;
720 if (i == (ssize_t) argc)
721 ThrowCompositeException(OptionError,"MissingArgument",option);
722 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,
725 ThrowCompositeException(OptionError,"UnrecognizedComposeOperator",
727 composite_options.compose=(CompositeOperator) compose;
730 if (LocaleCompare("compress",option+1) == 0)
738 if (i == (ssize_t) argc)
739 ThrowCompositeException(OptionError,"MissingArgument",option);
740 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
743 ThrowCompositeException(OptionError,
744 "UnrecognizedImageCompression",argv[i]);
747 if (LocaleCompare("concurrent",option+1) == 0)
749 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
753 if (LocaleCompare("debug",option+1) == 0)
761 if (i == (ssize_t) argc)
762 ThrowCompositeException(OptionError,"MissingArgument",option);
763 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
765 ThrowCompositeException(OptionError,"UnrecognizedEventType",
767 (void) SetLogEventMask(argv[i]);
770 if (LocaleCompare("decipher",option+1) == 0)
775 if (i == (ssize_t) (argc-1))
776 ThrowCompositeException(OptionError,"MissingArgument",option);
779 if (LocaleCompare("define",option+1) == 0)
782 if (i == (ssize_t) argc)
783 ThrowCompositeException(OptionError,"MissingArgument",option);
789 define=GetImageOption(image_info,argv[i]);
790 if (define == (const char *) NULL)
791 ThrowCompositeException(OptionError,"NoSuchOption",argv[i]);
796 if (LocaleCompare("density",option+1) == 0)
801 if (i == (ssize_t) argc)
802 ThrowCompositeException(OptionError,"MissingArgument",option);
803 if (IsGeometry(argv[i]) == MagickFalse)
804 ThrowCompositeInvalidArgumentException(option,argv[i]);
807 if (LocaleCompare("depth",option+1) == 0)
812 if (i == (ssize_t) argc)
813 ThrowCompositeException(OptionError,"MissingArgument",option);
814 if (IsGeometry(argv[i]) == MagickFalse)
815 ThrowCompositeInvalidArgumentException(option,argv[i]);
818 if (LocaleCompare("displace",option+1) == 0)
820 (void) CloneString(&composite_options.compose_args,(char *) NULL);
824 if (i == (ssize_t) argc)
825 ThrowCompositeException(OptionError,"MissingArgument",option);
826 if (IsGeometry(argv[i]) == MagickFalse)
827 ThrowCompositeInvalidArgumentException(option,argv[i]);
828 (void) CloneString(&composite_options.compose_args,argv[i]);
829 composite_options.compose=DisplaceCompositeOp;
832 if (LocaleCompare("display",option+1) == 0)
837 if (i == (ssize_t) argc)
838 ThrowCompositeException(OptionError,"MissingArgument",option);
841 if (LocaleCompare("dispose",option+1) == 0)
849 if (i == (ssize_t) argc)
850 ThrowCompositeException(OptionError,"MissingArgument",option);
851 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
853 ThrowCompositeException(OptionError,"UnrecognizedDisposeMethod",
857 if (LocaleCompare("dissolve",option+1) == 0)
859 (void) CloneString(&composite_options.compose_args,(char *) NULL);
863 if (i == (ssize_t) argc)
864 ThrowCompositeException(OptionError,"MissingArgument",option);
865 if (IsGeometry(argv[i]) == MagickFalse)
866 ThrowCompositeInvalidArgumentException(option,argv[i]);
867 (void) CloneString(&composite_options.compose_args,argv[i]);
868 composite_options.compose=DissolveCompositeOp;
871 if (LocaleCompare("distort",option+1) == 0)
873 (void) CloneString(&composite_options.compose_args,(char *) NULL);
877 if (i == (ssize_t) argc)
878 ThrowCompositeException(OptionError,"MissingArgument",option);
879 if (IsGeometry(argv[i]) == MagickFalse)
880 ThrowCompositeInvalidArgumentException(option,argv[i]);
881 (void) CloneString(&composite_options.compose_args,argv[i]);
882 composite_options.compose=DistortCompositeOp;
885 if (LocaleCompare("dither",option+1) == 0)
893 if (i == (ssize_t) argc)
894 ThrowCompositeException(OptionError,"MissingArgument",option);
895 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
897 ThrowCompositeException(OptionError,"UnrecognizedDitherMethod",
901 if (LocaleCompare("duration",option+1) == 0)
906 if (i == (ssize_t) (argc-1))
907 ThrowCompositeException(OptionError,"MissingArgument",option);
908 if (IsGeometry(argv[i]) == MagickFalse)
909 ThrowCompositeInvalidArgumentException(option,argv[i]);
912 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
916 if (LocaleCompare("encipher",option+1) == 0)
921 if (i == (ssize_t) (argc-1))
922 ThrowCompositeException(OptionError,"MissingArgument",option);
925 if (LocaleCompare("encoding",option+1) == 0)
930 if (i == (ssize_t) argc)
931 ThrowCompositeException(OptionError,"MissingArgument",option);
934 if (LocaleCompare("endian",option+1) == 0)
942 if (i == (ssize_t) argc)
943 ThrowCompositeException(OptionError,"MissingArgument",option);
944 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,
947 ThrowCompositeException(OptionError,"UnrecognizedEndianType",
951 if (LocaleCompare("extract",option+1) == 0)
956 if (i == (ssize_t) argc)
957 ThrowCompositeException(OptionError,"MissingArgument",option);
958 if (IsGeometry(argv[i]) == MagickFalse)
959 ThrowCompositeInvalidArgumentException(option,argv[i]);
962 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
966 if (LocaleCompare("filter",option+1) == 0)
974 if (i == (ssize_t) argc)
975 ThrowCompositeException(OptionError,"MissingArgument",option);
976 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
978 ThrowCompositeException(OptionError,"UnrecognizedImageFilter",
982 if (LocaleCompare("font",option+1) == 0)
987 if (i == (ssize_t) argc)
988 ThrowCompositeException(OptionError,"MissingArgument",option);
991 if (LocaleCompare("format",option+1) == 0)
996 if (i == (ssize_t) argc)
997 ThrowCompositeException(OptionError,"MissingArgument",option);
1001 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1005 if (LocaleCompare("geometry",option+1) == 0)
1007 (void) CloneString(&composite_options.geometry,(char *) NULL);
1011 if (i == (ssize_t) argc)
1012 ThrowCompositeException(OptionError,"MissingArgument",option);
1013 if (IsGeometry(argv[i]) == MagickFalse)
1014 ThrowCompositeInvalidArgumentException(option,argv[i]);
1015 (void) CloneString(&composite_options.geometry,argv[i]);
1018 if (LocaleCompare("gravity",option+1) == 0)
1023 composite_options.gravity=UndefinedGravity;
1027 if (i == (ssize_t) argc)
1028 ThrowCompositeException(OptionError,"MissingArgument",option);
1029 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,
1032 ThrowCompositeException(OptionError,"UnrecognizedGravityType",
1034 composite_options.gravity=(GravityType) gravity;
1037 if (LocaleCompare("green-primary",option+1) == 0)
1042 if (i == (ssize_t) argc)
1043 ThrowCompositeException(OptionError,"MissingArgument",option);
1044 if (IsGeometry(argv[i]) == MagickFalse)
1045 ThrowCompositeInvalidArgumentException(option,argv[i]);
1048 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1052 if ((LocaleCompare("help",option+1) == 0) ||
1053 (LocaleCompare("-help",option+1) == 0))
1054 return(CompositeUsage());
1055 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1059 if (LocaleCompare("identify",option+1) == 0)
1061 if (LocaleCompare("interlace",option+1) == 0)
1069 if (i == (ssize_t) argc)
1070 ThrowCompositeException(OptionError,"MissingArgument",option);
1071 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
1074 ThrowCompositeException(OptionError,
1075 "UnrecognizedInterlaceType",argv[i]);
1078 if (LocaleCompare("interpolate",option+1) == 0)
1086 if (i == (ssize_t) argc)
1087 ThrowCompositeException(OptionError,"MissingArgument",option);
1088 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
1090 if (interpolate < 0)
1091 ThrowCompositeException(OptionError,
1092 "UnrecognizedInterpolateMethod",argv[i]);
1095 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1099 if (LocaleCompare("label",option+1) == 0)
1104 if (i == (ssize_t) argc)
1105 ThrowCompositeException(OptionError,"MissingArgument",option);
1108 if (LocaleCompare("limit",option+1) == 0)
1122 if (i == (ssize_t) argc)
1123 ThrowCompositeException(OptionError,"MissingArgument",option);
1124 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
1127 ThrowCompositeException(OptionError,"UnrecognizedResourceType",
1130 if (i == (ssize_t) argc)
1131 ThrowCompositeException(OptionError,"MissingArgument",option);
1132 value=StringToDouble(argv[i],&p);
1134 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
1135 ThrowCompositeInvalidArgumentException(option,argv[i]);
1138 if (LocaleCompare("list",option+1) == 0)
1146 if (i == (ssize_t) argc)
1147 ThrowCompositeException(OptionError,"MissingArgument",option);
1148 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
1150 ThrowCompositeException(OptionError,"UnrecognizedListType",
1152 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
1155 return(status != 0 ? MagickFalse : MagickTrue);
1157 if (LocaleCompare("log",option+1) == 0)
1162 if ((i == (ssize_t) argc) || (strchr(argv[i],'%') == (char *) NULL))
1163 ThrowCompositeException(OptionError,"MissingArgument",option);
1166 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1170 if (LocaleCompare("matte",option+1) == 0)
1172 if (LocaleCompare("monitor",option+1) == 0)
1174 if (LocaleCompare("monochrome",option+1) == 0)
1176 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1180 if (LocaleCompare("negate",option+1) == 0)
1182 if (LocaleCompare("noop",option+1) == 0)
1184 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1188 if (LocaleCompare("page",option+1) == 0)
1193 if (i == (ssize_t) argc)
1194 ThrowCompositeException(OptionError,"MissingArgument",option);
1197 if (LocaleCompare("pointsize",option+1) == 0)
1202 if (i == (ssize_t) (argc-1))
1203 ThrowCompositeException(OptionError,"MissingArgument",option);
1204 if (IsGeometry(argv[i]) == MagickFalse)
1205 ThrowCompositeInvalidArgumentException(option,argv[i]);
1208 if (LocaleCompare("process",option+1) == 0)
1213 if (i == (ssize_t) argc)
1214 ThrowCompositeException(OptionError,"MissingArgument",option);
1217 if (LocaleCompare("profile",option+1) == 0)
1220 if (i == (ssize_t) argc)
1221 ThrowCompositeException(OptionError,"MissingArgument",option);
1224 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1228 if (LocaleCompare("quality",option+1) == 0)
1233 if (i == (ssize_t) argc)
1234 ThrowCompositeException(OptionError,"MissingArgument",option);
1235 if (IsGeometry(argv[i]) == MagickFalse)
1236 ThrowCompositeInvalidArgumentException(option,argv[i]);
1239 if (LocaleCompare("quantize",option+1) == 0)
1247 if (i == (ssize_t) (argc-1))
1248 ThrowCompositeException(OptionError,"MissingArgument",option);
1249 colorspace=ParseCommandOption(MagickColorspaceOptions,
1250 MagickFalse,argv[i]);
1252 ThrowCompositeException(OptionError,"UnrecognizedColorspace",
1256 if (LocaleCompare("quiet",option+1) == 0)
1258 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1262 if (LocaleCompare("red-primary",option+1) == 0)
1267 if (i == (ssize_t) argc)
1268 ThrowCompositeException(OptionError,"MissingArgument",option);
1269 if (IsGeometry(argv[i]) == MagickFalse)
1270 ThrowCompositeInvalidArgumentException(option,argv[i]);
1273 if (LocaleCompare("regard-warnings",option+1) == 0)
1275 if (LocaleCompare("render",option+1) == 0)
1277 if (LocaleCompare("repage",option+1) == 0)
1282 if (i == (ssize_t) argc)
1283 ThrowCompositeException(OptionError,"MissingArgument",option);
1284 if (IsGeometry(argv[i]) == MagickFalse)
1285 ThrowCompositeInvalidArgumentException(option,argv[i]);
1288 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
1290 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
1293 if (LocaleCompare("resize",option+1) == 0)
1298 if (i == (ssize_t) argc)
1299 ThrowCompositeException(OptionError,"MissingArgument",option);
1300 if (IsGeometry(argv[i]) == MagickFalse)
1301 ThrowCompositeInvalidArgumentException(option,argv[i]);
1304 if (LocaleCompare("rotate",option+1) == 0)
1307 if (i == (ssize_t) argc)
1308 ThrowCompositeException(OptionError,"MissingArgument",option);
1309 if (IsGeometry(argv[i]) == MagickFalse)
1310 ThrowCompositeInvalidArgumentException(option,argv[i]);
1313 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1317 if (LocaleCompare("sampling-factor",option+1) == 0)
1322 if (i == (ssize_t) argc)
1323 ThrowCompositeException(OptionError,"MissingArgument",option);
1324 if (IsGeometry(argv[i]) == MagickFalse)
1325 ThrowCompositeInvalidArgumentException(option,argv[i]);
1328 if (LocaleCompare("scene",option+1) == 0)
1333 if (i == (ssize_t) argc)
1334 ThrowCompositeException(OptionError,"MissingArgument",option);
1335 if (IsGeometry(argv[i]) == MagickFalse)
1336 ThrowCompositeInvalidArgumentException(option,argv[i]);
1339 if (LocaleCompare("seed",option+1) == 0)
1344 if (i == (ssize_t) (argc-1))
1345 ThrowCompositeException(OptionError,"MissingArgument",option);
1346 if (IsGeometry(argv[i]) == MagickFalse)
1347 ThrowCompositeInvalidArgumentException(option,argv[i]);
1350 if (LocaleCompare("sharpen",option+1) == 0)
1353 if (i == (ssize_t) argc)
1354 ThrowCompositeException(OptionError,"MissingArgument",option);
1355 if (IsGeometry(argv[i]) == MagickFalse)
1356 ThrowCompositeInvalidArgumentException(option,argv[i]);
1359 if (LocaleCompare("shave",option+1) == 0)
1364 if (i == (ssize_t) (argc-1))
1365 ThrowCompositeException(OptionError,"MissingArgument",option);
1366 if (IsGeometry(argv[i]) == MagickFalse)
1367 ThrowCompositeInvalidArgumentException(option,argv[i]);
1370 if (LocaleCompare("size",option+1) == 0)
1375 if (i == (ssize_t) argc)
1376 ThrowCompositeException(OptionError,"MissingArgument",option);
1377 if (IsGeometry(argv[i]) == MagickFalse)
1378 ThrowCompositeInvalidArgumentException(option,argv[i]);
1381 if (LocaleCompare("stegano",option+1) == 0)
1383 composite_options.stegano=0;
1387 if (i == (ssize_t) argc)
1388 ThrowCompositeException(OptionError,"MissingArgument",option);
1389 if (IsGeometry(argv[i]) == MagickFalse)
1390 ThrowCompositeInvalidArgumentException(option,argv[i]);
1391 composite_options.stegano=(ssize_t) StringToLong(argv[i])+1;
1394 if (LocaleCompare("stereo",option+1) == 0)
1399 composite_options.stereo=MagickFalse;
1403 if (i == (ssize_t) argc)
1404 ThrowCompositeException(OptionError,"MissingArgument",option);
1405 if (IsGeometry(argv[i]) == MagickFalse)
1406 ThrowCompositeInvalidArgumentException(option,argv[i]);
1407 flags=ParseAbsoluteGeometry(argv[i],&composite_options.offset);
1408 if ((flags & YValue) == 0)
1409 composite_options.offset.y=composite_options.offset.x;
1410 composite_options.stereo=MagickTrue;
1413 if (LocaleCompare("strip",option+1) == 0)
1415 if (LocaleCompare("support",option+1) == 0)
1417 i++; /* deprecated */
1420 if (LocaleCompare("swap",option+1) == 0)
1425 if (i == (ssize_t) (argc-1))
1426 ThrowCompositeException(OptionError,"MissingArgument",option);
1427 if (IsGeometry(argv[i]) == MagickFalse)
1428 ThrowCompositeInvalidArgumentException(option,argv[i]);
1431 if (LocaleCompare("synchronize",option+1) == 0)
1433 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1437 if (LocaleCompare("taint",option+1) == 0)
1439 if (LocaleCompare("thumbnail",option+1) == 0)
1444 if (i == (ssize_t) argc)
1445 ThrowCompositeException(OptionError,"MissingArgument",option);
1446 if (IsGeometry(argv[i]) == MagickFalse)
1447 ThrowCompositeInvalidArgumentException(option,argv[i]);
1450 if (LocaleCompare("tile",option+1) == 0)
1452 composite_options.tile=(*option == '-') ? MagickTrue : MagickFalse;
1453 (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
1456 if (LocaleCompare("transform",option+1) == 0)
1458 if (LocaleCompare("transparent-color",option+1) == 0)
1463 if (i == (ssize_t) (argc-1))
1464 ThrowCompositeException(OptionError,"MissingArgument",option);
1467 if (LocaleCompare("treedepth",option+1) == 0)
1472 if (i == (ssize_t) argc)
1473 ThrowCompositeException(OptionError,"MissingArgument",option);
1474 if (IsGeometry(argv[i]) == MagickFalse)
1475 ThrowCompositeInvalidArgumentException(option,argv[i]);
1478 if (LocaleCompare("type",option+1) == 0)
1486 if (i == (ssize_t) argc)
1487 ThrowCompositeException(OptionError,"MissingArgument",option);
1488 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
1490 ThrowCompositeException(OptionError,"UnrecognizedImageType",
1494 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1498 if (LocaleCompare("units",option+1) == 0)
1506 if (i == (ssize_t) argc)
1507 ThrowCompositeException(OptionError,"MissingArgument",option);
1508 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
1511 ThrowCompositeException(OptionError,"UnrecognizedUnitsType",
1515 if (LocaleCompare("unsharp",option+1) == 0)
1517 (void) CloneString(&composite_options.compose_args,(char *) NULL);
1521 if (i == (ssize_t) argc)
1522 ThrowCompositeException(OptionError,"MissingArgument",option);
1523 if (IsGeometry(argv[i]) == MagickFalse)
1524 ThrowCompositeInvalidArgumentException(option,argv[i]);
1525 (void) CloneString(&composite_options.compose_args,argv[i]);
1526 composite_options.compose=ThresholdCompositeOp;
1529 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1533 if (LocaleCompare("verbose",option+1) == 0)
1535 if ((LocaleCompare("version",option+1) == 0) ||
1536 (LocaleCompare("-version",option+1) == 0))
1538 ListMagickVersion(stdout);
1541 if (LocaleCompare("virtual-pixel",option+1) == 0)
1549 if (i == (ssize_t) argc)
1550 ThrowCompositeException(OptionError,"MissingArgument",option);
1551 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
1554 ThrowCompositeException(OptionError,
1555 "UnrecognizedVirtualPixelMethod",argv[i]);
1558 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1562 if (LocaleCompare("watermark",option+1) == 0)
1564 (void) CloneString(&composite_options.compose_args,(char *) NULL);
1568 if (i == (ssize_t) argc)
1569 ThrowCompositeException(OptionError,"MissingArgument",option);
1570 if (IsGeometry(argv[i]) == MagickFalse)
1571 ThrowCompositeInvalidArgumentException(option,argv[i]);
1572 (void) CloneString(&composite_options.compose_args,argv[i]);
1573 composite_options.compose=ModulateCompositeOp;
1576 if (LocaleCompare("white-point",option+1) == 0)
1581 if (i == (ssize_t) argc)
1582 ThrowCompositeException(OptionError,"MissingArgument",option);
1583 if (IsGeometry(argv[i]) == MagickFalse)
1584 ThrowCompositeInvalidArgumentException(option,argv[i]);
1587 if (LocaleCompare("write",option+1) == 0)
1590 if (i == (ssize_t) argc)
1591 ThrowCompositeException(OptionError,"MissingArgument",option);
1594 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1599 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1601 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
1602 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
1603 if (fire != MagickFalse)
1604 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
1607 ThrowCompositeException(OptionError,"UnbalancedParenthesis",argv[i]);
1608 if (i-- != (ssize_t) (argc-1))
1609 ThrowCompositeException(OptionError,"MissingAnImageFilename",argv[i]);
1610 if ((image == (Image *) NULL) || (GetImageListLength(image) < 2))
1611 ThrowCompositeException(OptionError,"MissingAnImageFilename",argv[argc-1]);
1612 FinalizeImageSettings(image_info,image,MagickTrue);
1613 if ((image == (Image *) NULL) || (GetImageListLength(image) < 2))
1614 ThrowCompositeException(OptionError,"MissingAnImageFilename",argv[argc-1]);
1618 RemoveImageStack(composite_image);
1619 RemoveImageStack(images);
1620 (void) TransformImage(&composite_image,(char *) NULL,
1621 composite_image->geometry,exception);
1622 RemoveImageStack(mask_image);
1623 if (mask_image != (Image *) NULL)
1625 if ((composite_options.compose == DisplaceCompositeOp) ||
1626 (composite_options.compose == DistortCompositeOp))
1627 status&=CompositeImage(composite_image,mask_image,
1628 CopyGreenCompositeOp,MagickTrue,0,0,exception);
1630 status&=CompositeImage(composite_image,mask_image,IntensityCompositeOp,
1631 MagickTrue,0,0,exception);
1632 mask_image=DestroyImage(mask_image);
1634 status&=CompositeImageList(image_info,&images,composite_image,
1635 &composite_options,exception);
1636 composite_image=DestroyImage(composite_image);
1638 Write composite images.
1640 status&=WriteImages(image_info,images,argv[argc-1],exception);
1641 if (metadata != (char **) NULL)
1646 text=InterpretImageProperties(image_info,images,format,exception);
1647 if (text == (char *) NULL)
1648 ThrowCompositeException(ResourceLimitError,"MemoryAllocationFailed",
1649 GetExceptionMessage(errno));
1650 (void) ConcatenateString(&(*metadata),text);
1651 text=DestroyString(text);
1653 images=DestroyImage(images);
1654 RelinquishCompositeOptions(&composite_options);
1656 return(status != 0 ? MagickTrue : MagickFalse);