javascript - Download image from data base to canvas -
i have problem. first add image computer canvas
document.getelementbyid('imgloader').onchange = function handleimage(e) { var reader = new filereader(); reader.onload = function (event) { console.log('fdsf'); var imgobj = new image(); imgobj.src = event.target.result; imgobj.onload = function () { // start fabricjs stuff var newsize = scalesize(300, 300, imgobj.width, imgobj.height); imgobj.width = newsize[0]; imgobj.height = newsize[1]; var image = new fabric.image(imgobj); image.set({ left: 0, top: 0, angle: 20, padding: 10, cornersize: 10 }); //image.scale(getrandomnum(0.1, 0.25)).setcoords(); canvas.add(image); // end fabricjs stuff } } reader.readasdataurl(e.target.files[0]);
}
next save data base string
json.stringify(canvas.tojson())
in data base see it:
{"objects":[{"type":"image","originx":"left","originy":"top","left":0,"top":0,"width":300,"height":155,"fill":"rgb(0,0,0)","stroke":null,"strokewidth":1,"strokedasharray":null,"strokelinecap":"butt","strokelinejoin":"miter","strokemiterlimit":10,"scalex":1,"scaley":1,"angle":20,"flipx":false,"flipy":false,"opacity":1,"shadow":null,"visible":true,"clipto":null,"backgroundcolor":"","src":"data:image/jpeg;base64,//.../z","filters":[],"crossorigin":""}],"background":""}
my problem here. when want download img canvas. dont see img. why?
i use method:
canvas.loadfromjson(data["img"][i]) document.getelementbyid("test").innerhtml=canvas.tosvg();
try:
canvas.loadfromjson(json, canvas.renderall.bind(canvas));
json
here variable has string json:
json = json.stringify(canvas.tojson());
it should work. made jsfiddle. canvas.clear()
there clear see load json works.
Comments
Post a Comment