javascript - Capturing entire canvas as an image - Fabric JS -
i'm creating designer angular 2 using fabric js in user adds background image , overlays text, shapes etc.
at stage, want able replicate canvas (in modal checkout screen) user can have thumbnail preview of design: preferably image.
is there built in fabric function allow this? or plugin might better suited?
here need
var canvas = new fabric.canvas('canvascontainer'); var rect = new fabric.rect({ left: 100, top: 100, fill: "#ff0000", stroke: "black", width: 100, height: 100, strokewidth: 10, }); canvas.add(rect); canvas.renderall(); var converttoimage=function(){ canvas.deactivateall().renderall(); document.getelementbyid("ten").src=canvas.todataurl('png'); } converttoimage();
<script src="https://rawgithub.com/kangax/fabric.js/master/dist/fabric.js"></script> <canvas width="400" height="400" id="canvascontainer"></canvas> <img id="ten" style="border:2px solid;"/>
here can see have not provided src image. instead function converttoimage set source of image. here fiddle
Comments
Post a Comment