Implemented PNG export

This commit is contained in:
Devine Lu Linvega
2017-11-10 08:47:06 +13:00
parent 2fde8ef16d
commit 86aaef5c81
5 changed files with 65 additions and 18 deletions

27
sources/scripts/render.js Normal file
View File

@@ -0,0 +1,27 @@
function Render()
{
this.el = document.createElement("canvas"); this.el.id = "render";
this.img = document.createElement("img");
this.el.width = 300; this.el.height = 300;
this.draw = function()
{
var xml = new XMLSerializer().serializeToString(dotgrid.svg_el);
var svg64 = btoa(xml);
var b64Start = 'data:image/svg+xml;base64,';
var image64 = b64Start + svg64;
this.img.src = image64;
this.el.getContext('2d').clearRect(0, 0, 300, 300);
this.el.getContext('2d').drawImage(this.img, 0, 0);
}
this.buffer = function()
{
var fs = require('fs');
var data = this.el.toDataURL('image/png').replace(/^data:image\/\w+;base64,/, "");
var buf = new Buffer(data, 'base64');
return buf
}
}