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-2017 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)
117 assert(image_info != (ImageInfo *) NULL);
118 assert(image_info->signature == MagickCoreSignature);
119 assert(image != (Image **) NULL);
120 assert((*image)->signature == MagickCoreSignature);
121 if ((*image)->debug != MagickFalse)
122 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
123 assert(exception != (ExceptionInfo *) NULL);
125 if (composite_image != (Image *) NULL)
130 channel_mask=SetImageChannelMask(composite_image,
131 composite_options->channel);
132 assert(composite_image->signature == MagickCoreSignature);
133 switch (composite_options->compose)
135 case BlendCompositeOp:
136 case BlurCompositeOp:
137 case DisplaceCompositeOp:
138 case DistortCompositeOp:
139 case DissolveCompositeOp:
140 case ModulateCompositeOp:
141 case ThresholdCompositeOp:
143 (void) SetImageArtifact(*image,"compose:args",
144 composite_options->compose_args);
153 if (composite_options->stegano != 0)
158 (*image)->offset=composite_options->stegano-1;
159 stegano_image=SteganoImage(*image,composite_image,exception);
160 if (stegano_image != (Image *) NULL)
162 *image=DestroyImageList(*image);
163 *image=stegano_image;
167 if (composite_options->stereo != MagickFalse)
172 stereo_image=StereoAnaglyphImage(*image,composite_image,
173 composite_options->offset.x,composite_options->offset.y,
175 if (stereo_image != (Image *) NULL)
177 *image=DestroyImageList(*image);
182 if (composite_options->tile != MagickFalse)
192 Tile the composite image.
194 (void) SetImageArtifact(*image,"compose:outside-overlay","false");
195 columns=composite_image->columns;
196 for (y=0; y < (ssize_t) (*image)->rows; y+=(ssize_t) composite_image->rows)
197 for (x=0; x < (ssize_t) (*image)->columns; x+=(ssize_t) columns)
198 status&=CompositeImage(*image,composite_image,
199 composite_options->compose,MagickTrue,x,y,exception);
207 Work out gravity Adjustment of Offset
209 SetGeometry(*image,&geometry);
210 (void) ParseAbsoluteGeometry(composite_options->geometry,
212 geometry.width=composite_image->columns;
213 geometry.height=composite_image->rows;
214 GravityAdjustGeometry((*image)->columns,(*image)->rows,
215 composite_options->gravity, &geometry);
216 (*image)->gravity=(GravityType) composite_options->gravity;
218 Digitally composite image.
220 status&=CompositeImage(*image,composite_image,
221 composite_options->compose,MagickTrue,geometry.x,geometry.y,
224 (void) SetPixelChannelMask(composite_image,channel_mask);
226 return(status != 0 ? MagickTrue : MagickFalse);
229 static MagickBooleanType CompositeUsage(void)
237 "-debug events display copious debugging information",
238 "-help print program options",
239 "-list type print a list of supported option arguments",
240 "-log format format of debugging information",
241 "-version print version information",
246 "-blend geometry blend images",
247 "-border geometry surround image with a border of color",
248 "-bordercolor color border color",
249 "-channel mask set the image channel mask",
250 "-colors value preferred number of colors in the image",
251 "-decipher filename convert cipher pixels to plain pixels",
252 "-displace geometry shift lookup according to a relative displacement map",
253 "-dissolve value dissolve the two images a given percent",
254 "-distort geometry shift lookup according to a absolute distortion map",
255 "-encipher filename convert plain pixels to cipher pixels",
256 "-extract geometry extract area from image",
257 "-geometry geometry location of the composite image",
258 "-identify identify the format and characteristics of the image",
259 "-monochrome transform image to black and white",
260 "-negate replace every pixel with its complementary color ",
261 "-profile filename add ICM or IPTC information profile to image",
262 "-quantize colorspace reduce colors in this colorspace",
263 "-repage geometry size and location of an image canvas (operator)",
264 "-rotate degrees apply Paeth rotation to the image",
265 "-resize geometry resize the image",
266 "-sharpen geometry sharpen the image",
267 "-shave geometry shave pixels from the image edges",
268 "-stegano offset hide watermark within an image",
269 "-stereo geometry combine two image to create a stereo anaglyph",
270 "-strip strip image of all profiles and comments",
271 "-thumbnail geometry create a thumbnail of the image",
272 "-transform affine transform image",
273 "-type type image type",
274 "-unsharp geometry sharpen the image",
275 "-watermark geometry percent brightness and saturation of a watermark",
276 "-write filename write images to this file",
281 "-affine matrix affine transform matrix",
282 "-alpha option on, activate, off, deactivate, set, opaque, copy",
283 " transparent, extract, background, or shape",
284 "-authenticate password",
285 " decipher image with this password",
286 "-blue-primary point chromaticity blue primary point",
287 "-colorspace type alternate image colorspace",
288 "-comment string annotate image with comment",
289 "-compose operator composite operator",
290 "-compress type type of pixel compression when writing the image",
291 "-define format:option",
292 " define one or more image format options",
293 "-depth value image depth",
294 "-density geometry horizontal and vertical density of the image",
295 "-display server get image or font from this X server",
296 "-dispose method layer disposal method",
297 "-dither method apply error diffusion to image",
298 "-encoding type text encoding type",
299 "-endian type endianness (MSB or LSB) of the image",
300 "-filter type use this filter when resizing an image",
301 "-font name render text with this font",
302 "-format \"string\" output formatted image characteristics",
303 "-gravity type which direction to gravitate towards",
304 "-green-primary point chromaticity green primary point",
305 "-interlace type type of image interlacing scheme",
306 "-interpolate method pixel color interpolation method",
307 "-label string assign a label to an image",
308 "-limit type value pixel cache resource limit",
309 "-matte store matte channel if the image has one",
310 "-monitor monitor progress",
311 "-page geometry size and location of an image canvas (setting)",
312 "-pointsize value font point size",
313 "-quality value JPEG/MIFF/PNG compression level",
314 "-quiet suppress all warning messages",
315 "-red-primary point chromaticity red primary point",
316 "-regard-warnings pay attention to warning messages",
317 "-respect-parentheses settings remain in effect until parenthesis boundary",
318 "-sampling-factor geometry",
319 " horizontal and vertical sampling factor",
320 "-scene value image scene number",
321 "-seed value seed a new sequence of pseudo-random numbers",
322 "-size geometry width and height of image",
323 "-support factor resize support: > 1.0 is blurry, < 1.0 is sharp",
324 "-synchronize synchronize image to storage device",
325 "-taint declare the image as modified",
326 "-transparent-color color",
327 " transparent color",
328 "-treedepth value color tree depth",
329 "-tile repeat composite operation across and down image",
330 "-units type the units of image resolution",
331 "-verbose print detailed information about the image",
332 "-virtual-pixel method",
333 " virtual pixel access method",
334 "-white-point point chromaticity white point",
339 "-swap indexes swap two images in the image sequence",
344 ListMagickVersion(stdout);
345 (void) printf("Usage: %s [options ...] image [options ...] composite\n"
346 " [ [options ...] mask ] [options ...] composite\n",
348 (void) printf("\nImage Settings:\n");
349 for (p=settings; *p != (char *) NULL; p++)
350 (void) printf(" %s\n",*p);
351 (void) printf("\nImage Operators:\n");
352 for (p=operators; *p != (char *) NULL; p++)
353 (void) printf(" %s\n",*p);
354 (void) printf("\nImage Stack Operators:\n");
355 for (p=stack_operators; *p != (char *) NULL; p++)
356 (void) printf(" %s\n",*p);
357 (void) printf("\nMiscellaneous Options:\n");
358 for (p=miscellaneous; *p != (char *) NULL; p++)
359 (void) printf(" %s\n",*p);
361 "\nBy default, the image format of 'file' is determined by its magic\n");
363 "number. To specify a particular image format, precede the filename\n");
365 "with an image format name and a colon (i.e. ps:image) or specify the\n");
367 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
368 (void) printf("'-' for standard input or output.\n");
372 static void GetCompositeOptions(CompositeOptions *composite_options)
374 (void) ResetMagickMemory(composite_options,0,sizeof(*composite_options));
375 composite_options->channel=DefaultChannels;
376 composite_options->compose=OverCompositeOp;
379 static void RelinquishCompositeOptions(CompositeOptions *composite_options)
381 if (composite_options->compose_args != (char *) NULL)
382 composite_options->compose_args=(char *)
383 RelinquishMagickMemory(composite_options->compose_args);
384 if (composite_options->geometry != (char *) NULL)
385 composite_options->geometry=(char *)
386 RelinquishMagickMemory(composite_options->geometry);
389 WandExport MagickBooleanType CompositeImageCommand(ImageInfo *image_info,
390 int argc,char **argv,char **metadata,ExceptionInfo *exception)
392 #define NotInitialized (unsigned int) (~0)
393 #define DestroyComposite() \
395 RelinquishCompositeOptions(&composite_options); \
396 DestroyImageStack(); \
397 for (i=0; i < (ssize_t) argc; i++) \
398 argv[i]=DestroyString(argv[i]); \
399 argv=(char **) RelinquishMagickMemory(argv); \
401 #define ThrowCompositeException(asperity,tag,option) \
403 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
404 option == (char *) NULL ? GetExceptionMessage(errno) : option); \
405 DestroyComposite(); \
406 return(MagickFalse); \
408 #define ThrowCompositeInvalidArgumentException(option,argument) \
410 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
411 "InvalidArgument","'%s': %s",option,argument); \
412 DestroyComposite(); \
413 return(MagickFalse); \
433 image_stack[MaxImageStackDepth+1];
453 assert(image_info != (ImageInfo *) NULL);
454 assert(image_info->signature == MagickCoreSignature);
455 if (image_info->debug != MagickFalse)
456 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
457 assert(exception != (ExceptionInfo *) NULL);
461 if ((LocaleCompare("version",option+1) == 0) ||
462 (LocaleCompare("-version",option+1) == 0))
464 ListMagickVersion(stdout);
469 return(CompositeUsage());
470 GetCompositeOptions(&composite_options);
471 filename=(char *) NULL;
476 option=(char *) NULL;
478 respect_parenthesis=MagickFalse;
481 Check command syntax.
483 composite_image=NewImageList();
484 image=NewImageList();
485 mask_image=NewImageList();
486 ReadCommandlLine(argc,&argv);
487 status=ExpandFilenames(&argc,&argv);
488 if (status == MagickFalse)
489 ThrowCompositeException(ResourceLimitError,"MemoryAllocationFailed",
490 GetExceptionMessage(errno));
491 for (i=1; i < (ssize_t) (argc-1); i++)
494 if (LocaleCompare(option,"(") == 0)
496 FireImageStack(MagickFalse,MagickTrue,pend);
497 if (k == MaxImageStackDepth)
498 ThrowCompositeException(OptionError,"ParenthesisNestedTooDeeply",
503 if (LocaleCompare(option,")") == 0)
505 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
507 ThrowCompositeException(OptionError,"UnableToParseExpression",option);
511 if (IsCommandOption(option) == MagickFalse)
516 FireImageStack(MagickFalse,MagickFalse,pend);
518 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
520 images=ReadImages(image_info,filename,exception);
521 status&=(images != (Image *) NULL) &&
522 (exception->severity < ErrorException);
523 if (images == (Image *) NULL)
525 AppendImageStack(images);
528 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
533 if (LocaleCompare("affine",option+1) == 0)
538 if (i == (ssize_t) argc)
539 ThrowCompositeException(OptionError,"MissingArgument",option);
540 if (IsGeometry(argv[i]) == MagickFalse)
541 ThrowCompositeInvalidArgumentException(option,argv[i]);
544 if (LocaleCompare("alpha",option+1) == 0)
552 if (i == (ssize_t) argc)
553 ThrowCompositeException(OptionError,"MissingArgument",option);
554 type=ParseCommandOption(MagickAlphaChannelOptions,MagickFalse,argv[i]);
556 ThrowCompositeException(OptionError,
557 "UnrecognizedAlphaChannelOption",argv[i]);
560 if (LocaleCompare("authenticate",option+1) == 0)
565 if (i == (ssize_t) argc)
566 ThrowCompositeException(OptionError,"MissingArgument",option);
569 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
573 if (LocaleCompare("background",option+1) == 0)
578 if (i == (ssize_t) argc)
579 ThrowCompositeException(OptionError,"MissingArgument",option);
582 if (LocaleCompare("blend",option+1) == 0)
584 (void) CloneString(&composite_options.compose_args,(char *) NULL);
588 if (i == (ssize_t) argc)
589 ThrowCompositeException(OptionError,"MissingArgument",option);
590 if (IsGeometry(argv[i]) == MagickFalse)
591 ThrowCompositeInvalidArgumentException(option,argv[i]);
592 (void) CloneString(&composite_options.compose_args,argv[i]);
593 composite_options.compose=BlendCompositeOp;
596 if (LocaleCompare("blur",option+1) == 0)
598 (void) CloneString(&composite_options.compose_args,(char *) NULL);
602 if (i == (ssize_t) argc)
603 ThrowCompositeException(OptionError,"MissingArgument",option);
604 if (IsGeometry(argv[i]) == MagickFalse)
605 ThrowCompositeInvalidArgumentException(option,argv[i]);
606 (void) CloneString(&composite_options.compose_args,argv[i]);
607 composite_options.compose=BlurCompositeOp;
610 if (LocaleCompare("blue-primary",option+1) == 0)
615 if (i == (ssize_t) argc)
616 ThrowCompositeException(OptionError,"MissingArgument",option);
617 if (IsGeometry(argv[i]) == MagickFalse)
618 ThrowCompositeInvalidArgumentException(option,argv[i]);
621 if (LocaleCompare("border",option+1) == 0)
626 if (i == (ssize_t) argc)
627 ThrowCompositeException(OptionError,"MissingArgument",option);
628 if (IsGeometry(argv[i]) == MagickFalse)
629 ThrowCompositeInvalidArgumentException(option,argv[i]);
632 if (LocaleCompare("bordercolor",option+1) == 0)
637 if (i == (ssize_t) argc)
638 ThrowCompositeException(OptionError,"MissingArgument",option);
641 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
645 if (LocaleCompare("cache",option+1) == 0)
650 if (i == (ssize_t) argc)
651 ThrowCompositeException(OptionError,"MissingArgument",option);
652 if (IsGeometry(argv[i]) == MagickFalse)
653 ThrowCompositeInvalidArgumentException(option,argv[i]);
656 if (LocaleCompare("channel",option+1) == 0)
663 composite_options.channel=DefaultChannels;
667 if (i == (ssize_t) argc)
668 ThrowCompositeException(OptionError,"MissingArgument",option);
669 channel=ParseChannelOption(argv[i]);
671 ThrowCompositeException(OptionError,"UnrecognizedChannelType",
673 composite_options.channel=(ChannelType) channel;
676 if (LocaleCompare("colors",option+1) == 0)
681 if (i == (ssize_t) argc)
682 ThrowCompositeException(OptionError,"MissingArgument",option);
683 if (IsGeometry(argv[i]) == MagickFalse)
684 ThrowCompositeInvalidArgumentException(option,argv[i]);
687 if (LocaleCompare("colorspace",option+1) == 0)
695 if (i == (ssize_t) argc)
696 ThrowCompositeException(OptionError,"MissingArgument",option);
697 colorspace=ParseCommandOption(MagickColorspaceOptions,
698 MagickFalse,argv[i]);
700 ThrowCompositeException(OptionError,"UnrecognizedColorspace",
704 if (LocaleCompare("comment",option+1) == 0)
709 if (i == (ssize_t) argc)
710 ThrowCompositeException(OptionError,"MissingArgument",option);
713 if (LocaleCompare("compose",option+1) == 0)
718 composite_options.compose=UndefinedCompositeOp;
722 if (i == (ssize_t) argc)
723 ThrowCompositeException(OptionError,"MissingArgument",option);
724 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,
727 ThrowCompositeException(OptionError,"UnrecognizedComposeOperator",
729 composite_options.compose=(CompositeOperator) compose;
732 if (LocaleCompare("compress",option+1) == 0)
740 if (i == (ssize_t) argc)
741 ThrowCompositeException(OptionError,"MissingArgument",option);
742 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
745 ThrowCompositeException(OptionError,
746 "UnrecognizedImageCompression",argv[i]);
749 if (LocaleCompare("concurrent",option+1) == 0)
751 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
755 if (LocaleCompare("debug",option+1) == 0)
763 if (i == (ssize_t) argc)
764 ThrowCompositeException(OptionError,"MissingArgument",option);
765 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
767 ThrowCompositeException(OptionError,"UnrecognizedEventType",
769 (void) SetLogEventMask(argv[i]);
772 if (LocaleCompare("decipher",option+1) == 0)
777 if (i == (ssize_t) argc)
778 ThrowCompositeException(OptionError,"MissingArgument",option);
781 if (LocaleCompare("define",option+1) == 0)
784 if (i == (ssize_t) argc)
785 ThrowCompositeException(OptionError,"MissingArgument",option);
791 define=GetImageOption(image_info,argv[i]);
792 if (define == (const char *) NULL)
793 ThrowCompositeException(OptionError,"NoSuchOption",argv[i]);
798 if (LocaleCompare("density",option+1) == 0)
803 if (i == (ssize_t) argc)
804 ThrowCompositeException(OptionError,"MissingArgument",option);
805 if (IsGeometry(argv[i]) == MagickFalse)
806 ThrowCompositeInvalidArgumentException(option,argv[i]);
809 if (LocaleCompare("depth",option+1) == 0)
814 if (i == (ssize_t) argc)
815 ThrowCompositeException(OptionError,"MissingArgument",option);
816 if (IsGeometry(argv[i]) == MagickFalse)
817 ThrowCompositeInvalidArgumentException(option,argv[i]);
820 if (LocaleCompare("displace",option+1) == 0)
822 (void) CloneString(&composite_options.compose_args,(char *) NULL);
826 if (i == (ssize_t) argc)
827 ThrowCompositeException(OptionError,"MissingArgument",option);
828 if (IsGeometry(argv[i]) == MagickFalse)
829 ThrowCompositeInvalidArgumentException(option,argv[i]);
830 (void) CloneString(&composite_options.compose_args,argv[i]);
831 composite_options.compose=DisplaceCompositeOp;
834 if (LocaleCompare("display",option+1) == 0)
839 if (i == (ssize_t) argc)
840 ThrowCompositeException(OptionError,"MissingArgument",option);
843 if (LocaleCompare("dispose",option+1) == 0)
851 if (i == (ssize_t) argc)
852 ThrowCompositeException(OptionError,"MissingArgument",option);
853 dispose=ParseCommandOption(MagickDisposeOptions,MagickFalse,argv[i]);
855 ThrowCompositeException(OptionError,"UnrecognizedDisposeMethod",
859 if (LocaleCompare("dissolve",option+1) == 0)
861 (void) CloneString(&composite_options.compose_args,(char *) NULL);
865 if (i == (ssize_t) argc)
866 ThrowCompositeException(OptionError,"MissingArgument",option);
867 if (IsGeometry(argv[i]) == MagickFalse)
868 ThrowCompositeInvalidArgumentException(option,argv[i]);
869 (void) CloneString(&composite_options.compose_args,argv[i]);
870 composite_options.compose=DissolveCompositeOp;
873 if (LocaleCompare("distort",option+1) == 0)
875 (void) CloneString(&composite_options.compose_args,(char *) NULL);
879 if (i == (ssize_t) argc)
880 ThrowCompositeException(OptionError,"MissingArgument",option);
881 if (IsGeometry(argv[i]) == MagickFalse)
882 ThrowCompositeInvalidArgumentException(option,argv[i]);
883 (void) CloneString(&composite_options.compose_args,argv[i]);
884 composite_options.compose=DistortCompositeOp;
887 if (LocaleCompare("dither",option+1) == 0)
895 if (i == (ssize_t) argc)
896 ThrowCompositeException(OptionError,"MissingArgument",option);
897 method=ParseCommandOption(MagickDitherOptions,MagickFalse,argv[i]);
899 ThrowCompositeException(OptionError,"UnrecognizedDitherMethod",
903 if (LocaleCompare("duration",option+1) == 0)
908 if (i == (ssize_t) argc)
909 ThrowCompositeException(OptionError,"MissingArgument",option);
910 if (IsGeometry(argv[i]) == MagickFalse)
911 ThrowCompositeInvalidArgumentException(option,argv[i]);
914 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
918 if (LocaleCompare("encipher",option+1) == 0)
923 if (i == (ssize_t) argc)
924 ThrowCompositeException(OptionError,"MissingArgument",option);
927 if (LocaleCompare("encoding",option+1) == 0)
932 if (i == (ssize_t) argc)
933 ThrowCompositeException(OptionError,"MissingArgument",option);
936 if (LocaleCompare("endian",option+1) == 0)
944 if (i == (ssize_t) argc)
945 ThrowCompositeException(OptionError,"MissingArgument",option);
946 endian=ParseCommandOption(MagickEndianOptions,MagickFalse,
949 ThrowCompositeException(OptionError,"UnrecognizedEndianType",
953 if (LocaleCompare("extract",option+1) == 0)
958 if (i == (ssize_t) argc)
959 ThrowCompositeException(OptionError,"MissingArgument",option);
960 if (IsGeometry(argv[i]) == MagickFalse)
961 ThrowCompositeInvalidArgumentException(option,argv[i]);
964 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
968 if (LocaleCompare("filter",option+1) == 0)
976 if (i == (ssize_t) argc)
977 ThrowCompositeException(OptionError,"MissingArgument",option);
978 filter=ParseCommandOption(MagickFilterOptions,MagickFalse,argv[i]);
980 ThrowCompositeException(OptionError,"UnrecognizedImageFilter",
984 if (LocaleCompare("font",option+1) == 0)
989 if (i == (ssize_t) argc)
990 ThrowCompositeException(OptionError,"MissingArgument",option);
993 if (LocaleCompare("format",option+1) == 0)
998 if (i == (ssize_t) argc)
999 ThrowCompositeException(OptionError,"MissingArgument",option);
1003 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1007 if (LocaleCompare("geometry",option+1) == 0)
1009 (void) CloneString(&composite_options.geometry,(char *) NULL);
1013 if (i == (ssize_t) argc)
1014 ThrowCompositeException(OptionError,"MissingArgument",option);
1015 if (IsGeometry(argv[i]) == MagickFalse)
1016 ThrowCompositeInvalidArgumentException(option,argv[i]);
1017 (void) CloneString(&composite_options.geometry,argv[i]);
1020 if (LocaleCompare("gravity",option+1) == 0)
1025 composite_options.gravity=UndefinedGravity;
1029 if (i == (ssize_t) argc)
1030 ThrowCompositeException(OptionError,"MissingArgument",option);
1031 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,
1034 ThrowCompositeException(OptionError,"UnrecognizedGravityType",
1036 composite_options.gravity=(GravityType) gravity;
1039 if (LocaleCompare("green-primary",option+1) == 0)
1044 if (i == (ssize_t) argc)
1045 ThrowCompositeException(OptionError,"MissingArgument",option);
1046 if (IsGeometry(argv[i]) == MagickFalse)
1047 ThrowCompositeInvalidArgumentException(option,argv[i]);
1050 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1054 if ((LocaleCompare("help",option+1) == 0) ||
1055 (LocaleCompare("-help",option+1) == 0))
1056 return(CompositeUsage());
1057 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1061 if (LocaleCompare("identify",option+1) == 0)
1063 if (LocaleCompare("interlace",option+1) == 0)
1071 if (i == (ssize_t) argc)
1072 ThrowCompositeException(OptionError,"MissingArgument",option);
1073 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
1076 ThrowCompositeException(OptionError,
1077 "UnrecognizedInterlaceType",argv[i]);
1080 if (LocaleCompare("interpolate",option+1) == 0)
1088 if (i == (ssize_t) argc)
1089 ThrowCompositeException(OptionError,"MissingArgument",option);
1090 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
1092 if (interpolate < 0)
1093 ThrowCompositeException(OptionError,
1094 "UnrecognizedInterpolateMethod",argv[i]);
1097 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1101 if (LocaleCompare("label",option+1) == 0)
1106 if (i == (ssize_t) argc)
1107 ThrowCompositeException(OptionError,"MissingArgument",option);
1110 if (LocaleCompare("limit",option+1) == 0)
1124 if (i == (ssize_t) argc)
1125 ThrowCompositeException(OptionError,"MissingArgument",option);
1126 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
1129 ThrowCompositeException(OptionError,"UnrecognizedResourceType",
1132 if (i == (ssize_t) argc)
1133 ThrowCompositeException(OptionError,"MissingArgument",option);
1134 value=StringToDouble(argv[i],&p);
1136 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
1137 ThrowCompositeInvalidArgumentException(option,argv[i]);
1140 if (LocaleCompare("list",option+1) == 0)
1148 if (i == (ssize_t) argc)
1149 ThrowCompositeException(OptionError,"MissingArgument",option);
1150 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
1152 ThrowCompositeException(OptionError,"UnrecognizedListType",
1154 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
1157 return(status == 0 ? MagickTrue : MagickFalse);
1159 if (LocaleCompare("log",option+1) == 0)
1164 if ((i == (ssize_t) argc) || (strchr(argv[i],'%') == (char *) NULL))
1165 ThrowCompositeException(OptionError,"MissingArgument",option);
1168 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1172 if (LocaleCompare("matte",option+1) == 0)
1174 if (LocaleCompare("monitor",option+1) == 0)
1176 if (LocaleCompare("monochrome",option+1) == 0)
1178 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1182 if (LocaleCompare("negate",option+1) == 0)
1184 if (LocaleCompare("noop",option+1) == 0)
1186 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1190 if (LocaleCompare("page",option+1) == 0)
1195 if (i == (ssize_t) argc)
1196 ThrowCompositeException(OptionError,"MissingArgument",option);
1199 if (LocaleCompare("pointsize",option+1) == 0)
1204 if (i == (ssize_t) argc)
1205 ThrowCompositeException(OptionError,"MissingArgument",option);
1206 if (IsGeometry(argv[i]) == MagickFalse)
1207 ThrowCompositeInvalidArgumentException(option,argv[i]);
1210 if (LocaleCompare("process",option+1) == 0)
1215 if (i == (ssize_t) argc)
1216 ThrowCompositeException(OptionError,"MissingArgument",option);
1219 if (LocaleCompare("profile",option+1) == 0)
1222 if (i == (ssize_t) argc)
1223 ThrowCompositeException(OptionError,"MissingArgument",option);
1226 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1230 if (LocaleCompare("quality",option+1) == 0)
1235 if (i == (ssize_t) argc)
1236 ThrowCompositeException(OptionError,"MissingArgument",option);
1237 if (IsGeometry(argv[i]) == MagickFalse)
1238 ThrowCompositeInvalidArgumentException(option,argv[i]);
1241 if (LocaleCompare("quantize",option+1) == 0)
1249 if (i == (ssize_t) argc)
1250 ThrowCompositeException(OptionError,"MissingArgument",option);
1251 colorspace=ParseCommandOption(MagickColorspaceOptions,
1252 MagickFalse,argv[i]);
1254 ThrowCompositeException(OptionError,"UnrecognizedColorspace",
1258 if (LocaleCompare("quiet",option+1) == 0)
1260 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1264 if (LocaleCompare("red-primary",option+1) == 0)
1269 if (i == (ssize_t) argc)
1270 ThrowCompositeException(OptionError,"MissingArgument",option);
1271 if (IsGeometry(argv[i]) == MagickFalse)
1272 ThrowCompositeInvalidArgumentException(option,argv[i]);
1275 if (LocaleCompare("regard-warnings",option+1) == 0)
1277 if (LocaleCompare("render",option+1) == 0)
1279 if (LocaleCompare("repage",option+1) == 0)
1284 if (i == (ssize_t) argc)
1285 ThrowCompositeException(OptionError,"MissingArgument",option);
1286 if (IsGeometry(argv[i]) == MagickFalse)
1287 ThrowCompositeInvalidArgumentException(option,argv[i]);
1290 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
1292 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
1295 if (LocaleCompare("resize",option+1) == 0)
1300 if (i == (ssize_t) argc)
1301 ThrowCompositeException(OptionError,"MissingArgument",option);
1302 if (IsGeometry(argv[i]) == MagickFalse)
1303 ThrowCompositeInvalidArgumentException(option,argv[i]);
1306 if (LocaleCompare("rotate",option+1) == 0)
1309 if (i == (ssize_t) argc)
1310 ThrowCompositeException(OptionError,"MissingArgument",option);
1311 if (IsGeometry(argv[i]) == MagickFalse)
1312 ThrowCompositeInvalidArgumentException(option,argv[i]);
1315 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1319 if (LocaleCompare("sampling-factor",option+1) == 0)
1324 if (i == (ssize_t) argc)
1325 ThrowCompositeException(OptionError,"MissingArgument",option);
1326 if (IsGeometry(argv[i]) == MagickFalse)
1327 ThrowCompositeInvalidArgumentException(option,argv[i]);
1330 if (LocaleCompare("scene",option+1) == 0)
1335 if (i == (ssize_t) argc)
1336 ThrowCompositeException(OptionError,"MissingArgument",option);
1337 if (IsGeometry(argv[i]) == MagickFalse)
1338 ThrowCompositeInvalidArgumentException(option,argv[i]);
1341 if (LocaleCompare("seed",option+1) == 0)
1346 if (i == (ssize_t) argc)
1347 ThrowCompositeException(OptionError,"MissingArgument",option);
1348 if (IsGeometry(argv[i]) == MagickFalse)
1349 ThrowCompositeInvalidArgumentException(option,argv[i]);
1352 if (LocaleCompare("sharpen",option+1) == 0)
1355 if (i == (ssize_t) argc)
1356 ThrowCompositeException(OptionError,"MissingArgument",option);
1357 if (IsGeometry(argv[i]) == MagickFalse)
1358 ThrowCompositeInvalidArgumentException(option,argv[i]);
1361 if (LocaleCompare("shave",option+1) == 0)
1366 if (i == (ssize_t) argc)
1367 ThrowCompositeException(OptionError,"MissingArgument",option);
1368 if (IsGeometry(argv[i]) == MagickFalse)
1369 ThrowCompositeInvalidArgumentException(option,argv[i]);
1372 if (LocaleCompare("size",option+1) == 0)
1377 if (i == (ssize_t) argc)
1378 ThrowCompositeException(OptionError,"MissingArgument",option);
1379 if (IsGeometry(argv[i]) == MagickFalse)
1380 ThrowCompositeInvalidArgumentException(option,argv[i]);
1383 if (LocaleCompare("stegano",option+1) == 0)
1385 composite_options.stegano=0;
1389 if (i == (ssize_t) argc)
1390 ThrowCompositeException(OptionError,"MissingArgument",option);
1391 if (IsGeometry(argv[i]) == MagickFalse)
1392 ThrowCompositeInvalidArgumentException(option,argv[i]);
1393 composite_options.stegano=(ssize_t) StringToLong(argv[i])+1;
1396 if (LocaleCompare("stereo",option+1) == 0)
1401 composite_options.stereo=MagickFalse;
1405 if (i == (ssize_t) argc)
1406 ThrowCompositeException(OptionError,"MissingArgument",option);
1407 if (IsGeometry(argv[i]) == MagickFalse)
1408 ThrowCompositeInvalidArgumentException(option,argv[i]);
1409 flags=ParseAbsoluteGeometry(argv[i],&composite_options.offset);
1410 if ((flags & YValue) == 0)
1411 composite_options.offset.y=composite_options.offset.x;
1412 composite_options.stereo=MagickTrue;
1415 if (LocaleCompare("strip",option+1) == 0)
1417 if (LocaleCompare("support",option+1) == 0)
1419 i++; /* deprecated */
1422 if (LocaleCompare("swap",option+1) == 0)
1427 if (i == (ssize_t) argc)
1428 ThrowCompositeException(OptionError,"MissingArgument",option);
1429 if (IsGeometry(argv[i]) == MagickFalse)
1430 ThrowCompositeInvalidArgumentException(option,argv[i]);
1433 if (LocaleCompare("synchronize",option+1) == 0)
1435 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1439 if (LocaleCompare("taint",option+1) == 0)
1441 if (LocaleCompare("thumbnail",option+1) == 0)
1446 if (i == (ssize_t) argc)
1447 ThrowCompositeException(OptionError,"MissingArgument",option);
1448 if (IsGeometry(argv[i]) == MagickFalse)
1449 ThrowCompositeInvalidArgumentException(option,argv[i]);
1452 if (LocaleCompare("tile",option+1) == 0)
1454 composite_options.tile=(*option == '-') ? MagickTrue : MagickFalse;
1455 (void) CopyMagickString(argv[i]+1,"sans",MagickPathExtent);
1458 if (LocaleCompare("transform",option+1) == 0)
1460 if (LocaleCompare("transparent-color",option+1) == 0)
1465 if (i == (ssize_t) argc)
1466 ThrowCompositeException(OptionError,"MissingArgument",option);
1469 if (LocaleCompare("treedepth",option+1) == 0)
1474 if (i == (ssize_t) argc)
1475 ThrowCompositeException(OptionError,"MissingArgument",option);
1476 if (IsGeometry(argv[i]) == MagickFalse)
1477 ThrowCompositeInvalidArgumentException(option,argv[i]);
1480 if (LocaleCompare("type",option+1) == 0)
1488 if (i == (ssize_t) argc)
1489 ThrowCompositeException(OptionError,"MissingArgument",option);
1490 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
1492 ThrowCompositeException(OptionError,"UnrecognizedImageType",
1496 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1500 if (LocaleCompare("units",option+1) == 0)
1508 if (i == (ssize_t) argc)
1509 ThrowCompositeException(OptionError,"MissingArgument",option);
1510 units=ParseCommandOption(MagickResolutionOptions,MagickFalse,
1513 ThrowCompositeException(OptionError,"UnrecognizedUnitsType",
1517 if (LocaleCompare("unsharp",option+1) == 0)
1519 (void) CloneString(&composite_options.compose_args,(char *) NULL);
1523 if (i == (ssize_t) argc)
1524 ThrowCompositeException(OptionError,"MissingArgument",option);
1525 if (IsGeometry(argv[i]) == MagickFalse)
1526 ThrowCompositeInvalidArgumentException(option,argv[i]);
1527 (void) CloneString(&composite_options.compose_args,argv[i]);
1528 composite_options.compose=ThresholdCompositeOp;
1531 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1535 if (LocaleCompare("verbose",option+1) == 0)
1537 if ((LocaleCompare("version",option+1) == 0) ||
1538 (LocaleCompare("-version",option+1) == 0))
1540 ListMagickVersion(stdout);
1543 if (LocaleCompare("virtual-pixel",option+1) == 0)
1551 if (i == (ssize_t) argc)
1552 ThrowCompositeException(OptionError,"MissingArgument",option);
1553 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
1556 ThrowCompositeException(OptionError,
1557 "UnrecognizedVirtualPixelMethod",argv[i]);
1560 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1564 if (LocaleCompare("watermark",option+1) == 0)
1566 (void) CloneString(&composite_options.compose_args,(char *) NULL);
1570 if (i == (ssize_t) argc)
1571 ThrowCompositeException(OptionError,"MissingArgument",option);
1572 if (IsGeometry(argv[i]) == MagickFalse)
1573 ThrowCompositeInvalidArgumentException(option,argv[i]);
1574 (void) CloneString(&composite_options.compose_args,argv[i]);
1575 composite_options.compose=ModulateCompositeOp;
1578 if (LocaleCompare("white-point",option+1) == 0)
1583 if (i == (ssize_t) argc)
1584 ThrowCompositeException(OptionError,"MissingArgument",option);
1585 if (IsGeometry(argv[i]) == MagickFalse)
1586 ThrowCompositeInvalidArgumentException(option,argv[i]);
1589 if (LocaleCompare("write",option+1) == 0)
1592 if (i == (ssize_t) argc)
1593 ThrowCompositeException(OptionError,"MissingArgument",option);
1596 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1601 ThrowCompositeException(OptionError,"UnrecognizedOption",option)
1603 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
1604 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
1605 if (fire != MagickFalse)
1606 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
1609 ThrowCompositeException(OptionError,"UnbalancedParenthesis",argv[i]);
1610 if (i-- != (ssize_t) (argc-1))
1611 ThrowCompositeException(OptionError,"MissingAnImageFilename",argv[i]);
1612 if ((image == (Image *) NULL) || (GetImageListLength(image) < 2))
1613 ThrowCompositeException(OptionError,"MissingAnImageFilename",argv[argc-1]);
1614 FinalizeImageSettings(image_info,image,MagickTrue);
1615 if ((image == (Image *) NULL) || (GetImageListLength(image) < 2))
1616 ThrowCompositeException(OptionError,"MissingAnImageFilename",argv[argc-1]);
1620 RemoveImageStack(composite_image);
1621 RemoveImageStack(images);
1622 if (composite_image->geometry != (char *) NULL)
1627 (void) ParseRegionGeometry(composite_image,composite_image->geometry,
1628 &resize_geometry,exception);
1629 if ((composite_image->columns != resize_geometry.width) ||
1630 (composite_image->rows != resize_geometry.height))
1635 resize_image=ResizeImage(composite_image,resize_geometry.width,
1636 resize_geometry.height,composite_image->filter,exception);
1637 if (resize_image != (Image *) NULL)
1639 composite_image=DestroyImage(composite_image);
1640 composite_image=resize_image;
1644 RemoveImageStack(mask_image);
1645 if (mask_image != (Image *) NULL)
1647 if ((composite_options.compose == DisplaceCompositeOp) ||
1648 (composite_options.compose == DistortCompositeOp))
1649 status&=CompositeImage(composite_image,mask_image,
1650 CopyGreenCompositeOp,MagickTrue,0,0,exception);
1652 status&=CompositeImage(composite_image,mask_image,IntensityCompositeOp,
1653 MagickTrue,0,0,exception);
1654 mask_image=DestroyImage(mask_image);
1656 status&=CompositeImageList(image_info,&images,composite_image,
1657 &composite_options,exception);
1658 composite_image=DestroyImage(composite_image);
1660 Write composite images.
1662 status&=WriteImages(image_info,images,argv[argc-1],exception);
1663 if (metadata != (char **) NULL)
1668 text=InterpretImageProperties(image_info,images,format,exception);
1669 if (text == (char *) NULL)
1670 ThrowCompositeException(ResourceLimitError,"MemoryAllocationFailed",
1671 GetExceptionMessage(errno));
1672 (void) ConcatenateString(&(*metadata),text);
1673 text=DestroyString(text);
1675 images=DestroyImage(images);
1676 RelinquishCompositeOptions(&composite_options);
1678 return(status != 0 ? MagickTrue : MagickFalse);