Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing fabric.js to render and manipulate server-side canvas in node.js
    primarykey
    data
    text
    <p>I'm trying to use fabric.js (v0.9.21, installed via npm on ubuntu 12.04) with node.js to render a canvas on the server (which can later be manipulated and extended without clientside interaction). To experiment, I've created a simple canvas on the clientside, and then exported it to JSON using <code>canvas.toJSON()</code> method. When I try to reload the canvas using just that JSON, it works great (utilizing <code>canvas.loadFromJSON()</code>). </p> <h3>You can see the entire example <a href="http://jsfiddle.net/4Vgce/" rel="nofollow">in this fiddle</a>.</h3> <p>(if it doesn't work, then the image probably expired - replace the link). </p> <p>I then try to do the exact same thing on the server side using this simple script:</p> <pre><code>var fabric = require('fabric').fabric; var fs = require('fs'); var canvas = fabric.createCanvasForNode(570, 600); fs.readFile('kitty.json', 'utf8', function(err, data) { canvas.loadFromJSON(data); }); </code></pre> <p>I get a strange crash when I run this script (using <code>node script.js</code> or <code>require('./script.js') from inside node</code>):</p> <pre><code>&gt; http.createClient is deprecated. Use `http.request` instead. /usr/lib/node_modules/fabric/dist/all.js:12429 ctx.drawImage( ^ Error: Image given has not completed loading at klass.fabric.Image.fabric.util.createClass._render (/usr/lib/node_modules/fabric/dist/all.js:12429:11) at klass.fabric.Image.fabric.util.createClass.render (/usr/lib/node_modules/fabric/dist/all.js:12303:12) at klass.(anonymous function) [as render] (/usr/lib/node_modules/fabric/dist/all.js:2405:48) at extend._draw (/usr/lib/node_modules/fabric/dist/all.js:5332:16) at extend.renderAll (/usr/lib/node_modules/fabric/dist/all.js:5468:16) at extend.insertAt (/usr/lib/node_modules/fabric/dist/all.js:5381:37) at fabric.util.object.extend._enlivenObjects (/usr/lib/node_modules/fabric/dist/all.js:7694:15) at Array.forEach (native) at fabric.util.object.extend._enlivenObjects (/usr/lib/node_modules/fabric/dist/all.js:7693:24) at onLoaded (/usr/lib/node_modules/fabric/dist/all.js:1995:11) </code></pre> <p>The canvas has a single image in it courtesy of interwebs' kitten collection, and one text item.</p> <p>I'm fairly new to node, so perhaps I've missed something along the way - any tips will be great. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload