Ciro Santilli OurBigBook.com $£ Sponsor €¥ 中国独裁统治 China Dictatorship 新疆改造中心、六四事件、法轮功、郝海东、709大抓捕、2015巴拿马文件 邓家贵、低端人口、西藏骚乱
two-js/common.js
const fs = require('fs');
const path = require('path');

const Canvas = require('canvas');
const Two = require('two.js')

function render(filename, draw, width=200, height=100) {
  const canvas = Canvas.createCanvas(width, height, 'svg');
  Two.Utils.shim(canvas, Canvas.Image);
  const two = new Two({
    width: width,
    height: height,
    domElement: canvas
  });
  const background = two.makeRectangle(width/2, height/2, width, height);
  background.fill = 'white';
  draw(two);
  two.render();
  const filename_noext = path.parse(filename).name;
  fs.writeFileSync(path.resolve(filename_noext + '.svg'), canvas.toBuffer('image/svg'));
}
exports.render = render;