javascript - KineticJs - Merging an image onto another -
i'd know if there way in kinetic have image merged image on lower layer, creating kind of crop effect based on shape of "cropping" image.
the image must have transparent background result, main source of difficulty me. otherwise have used mask dragging turned off... i've made diagram explain want bit better. suggestions welcome.
i've made quick jsfiddle, contents of image displayed inside box. feel 1 layer
way go on one.
you can use offscreen canvas element plus compositing create clipped image use kinetic.image. note offscreen canvas can used image source kinetic.image.
example code , demo: http://jsfiddle.net/m1erickson/ks1xxqfl/
var canvas=document.createelement('canvas'); var ctx=canvas.getcontext('2d'); canvas.width=background.width; canvas.height=background.height; ctx.drawimage(mask,0,0,mask.width*2.25,mask.height*2.25); ctx.globalcompositeoperation='source-in'; ctx.drawimage(background,0,0); var support=new kinetic.image({ draggable:true, image:canvas, }); layer.add(support); layer.draw();
illustrations
- left: background image,
- center: image used clipping mask
- right: background clipped mask (mask scaled 2.25x)
Comments
Post a Comment