html - How to hide the overflow of photos in canvas? -
i trying making photo frame pattern on canvas. in want put two, 3 or maybe more photos under overlay frame. few parts of overlay frame transparent.
if upload photo1 first section of frame visible second section , uploading photo2 section 2 visible first section. depending on photo uploaded first or edited @ last overlapping other photo.
i want know how hide overflow of photo should not visible other sections. how can achieve this?
i have done far:
canvas.on({ 'object:moving': onchange, 'object:scaling': onchange, 'object:rotating': onchange, }); function onchange(options) { options.target.setcoords(); canvas.foreachobject(function (obj) { if (obj === options.target) return; if (obj.id != 'cover1' && obj.id != 'cover2') return; if (options.target.intersectswithobject(obj)) { // hide portion canvas.renderall(); } }); }
kindly provide me best solution
you need apply clipto() method onto image.
var canvas; $(function(){ canvas = window._canvas = new fabric.canvas('canvas'); var radius = 200; fabric.image.fromurl('http://fabricjs.com/assets/pug_small.jpg', function(img) { img.scale(0.5).set({ left: 250, top: 250, angle: -15, clipto: function (ctx) { ctx.arc(0, 0, radius, 0, math.pi * 2, true); } }); canvas.add(img).setactiveobject(img); }); });
this fiddle show technique
Comments
Post a Comment