// Last updated 2010/08/05 09:50 /* https://imagemagick.dev.org.tw/discourse-server/viewtopic.php?f=10&t=12285 and more recently: https://imagemagick.dev.org.tw/discourse-server/viewtopic.php?f=1&t=16783 https://imagemagick.dev.org.tw/Usage/channels/#masked_compose Replicate a masked composite: convert -size 100x100 tile:tile_water.jpg tile:tile_disks.jpg \ mask_bite.png -composite compose_masked.png When doing composites in C it is best to think of the order that is used in the convert command because that is the order you will specify them in the MagickCompositeImage function. */ #include <windows.h> #include <wand/magick_wand.h> void test_wand(LPTSTR lpCmdLine) { MagickWand *dest = NULL, *src = NULL, *mask = NULL; MagickWandGenesis(); /* Create the wands */ dest = NewMagickWand(); mask = NewMagickWand(); src = NewMagickWand(); MagickSetSize(dest,100,100); MagickSetSize(src,100,100); MagickReadImage(dest,"tile:tile_water.jpg"); MagickReadImage(mask,"mask_bite.png"); // When you create a mask, you use white for those parts that you want // to show through and black for those which must not show through. // But internally it's the opposite so the mask must be negated MagickNegateImage(mask,MagickFalse); MagickSetImageClipMask(dest,mask); MagickReadImage(src,"tile:tile_disks.jpg"); // This does the src (overlay) over the dest (background) MagickCompositeImage(dest,src,OverCompositeOp,0,0); MagickWriteImage(dest,"clip_out.jpg"); /* Tidy up */ if(dest)dest = DestroyMagickWand(dest); if(mask)mask = DestroyMagickWand(mask); if(src)src = DestroyMagickWand(src); MagickWandTerminus(); }