How to use the fabric.fabric.createCanvasForNode function in fabric

To help you get started, we’ve selected a few fabric examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JuhoKang / bigpicture-light / config / pngConvertModule.js View on Github external
}).exec().then((chunk) => {
    // if nothing exists a cell with null data returns.
    if (chunk != null) {
      const tempCanvas = fabric.createCanvasForNode(CANVAS_SIZE, CANVAS_SIZE);
      tempCanvas.loadFromJSON(chunk.data, (done) => {
        const dataUrl = tempCanvas.toDataURL({ width: CANVAS_SIZE, height: CANVAS_SIZE });
        const modPng = dataUrl.substring(22, dataUrl.length);
        //console.log(modPng);
        sharp(new Buffer(modPng, "base64"))
          .resize(size, size)
          .toBuffer()
          .then(result => {
            debug(`done resize png ${x},${y}`);
            //console.log(`png update done ${x},${y}`)
            paintPngController.paintpng_save(x, y, size, result.toString("base64")).then(() => {
              //debug(result);
              debug(`done update png ${x},${y}`)
            });
            //pngs[`${x},${y}`] = result.toString("base64");
          }).catch(err => { debug(err) });
github JuhoKang / bigpicture-light / config / socket.js View on Github external
}).exec().then((chunk) => {
          // if nothing exists a cell with null data returns.
          if (chunk != null) {
            chunks[`${x},${y}`] = fabric.createCanvasForNode(CANVAS_SIZE, CANVAS_SIZE);
            chunks[`${x},${y}`].loadFromJSON(chunk.data, (done) => {
              resolve(chunks[`${x},${y}`]);
            });
          } else {
            resolve("chunk is null");
            //no chunk data from database
            //console.log("chunk is null");
          }
        }, (err) => {
          debug(err);
github shyiko / canvas-text-opentypejs-shim / demo / demo-runkit-fabric.js View on Github external
.then(() => {
    const font = opentype.loadSync('OpenSans-Regular.ttf')

    const ctx = fabric.createCanvasForNode(200, 200)
    const shimConfig = {
      resolveFont: function (o) {
        if (splitFontFamily(o.fontFamily)[0] === 'Open Sans') {
          return font
        }
      }
    }

    ctx.add(new fabric.Text('Hello World', {
      left: -0.5, top: -0.5, fontFamily: 'Open Sans', fontSize: 26,
      openTypeJsShimConfig: shimConfig
    }))

    console.log(`<img src="${ctx.toDataURL()}">`)
  })
github Objelisks / lsystembot / lsystem.js View on Github external
exports.expand = function(system, minLength) {
  //var canvas = new Canvas(width, height, 'svg');
  var canvas = fabric.createCanvasForNode(width, height);
  //var ctx = canvas.getContext('2d');

  var start = system.start;
  var rules = system.rules;
  var angle = system['a'] || chooseRandom([36, 45, 60, 90, Math.random()*360, Math.random()*360]);
  angle = angle * Math.PI / 180;
  var iterations = system.iter || chooseRandom([3, 4, 5, 6, 7, 8, 9]);
  var hue = Math.random()*360;
  var saturation = Math.random()*0.8 + 0.1;
  var lightness = Math.random()*0.8 + 0.1;
  lightness -= Math.abs(0.5-lightness) &lt; 0.2 ? 0.3 : 0;
  var fgColor = `hsl(${hue}, ${saturation*100}%, ${lightness*100}%)`;
  var bgColor = `hsl(${hue}, ${saturation*100}%, ${100-lightness*100}%)`;

  var iterate = function(str, rules) {
      var out = '', result;