node-canvas engine for spritesmith
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
lib Removed old TODO Nov 18, 2015
test Updated documentation and references to main Nov 12, 2015
.gitignore Initial transplant/tweaks from gmsmith Apr 28, 2013
.jshintrc Replaced grunt with twolfson-style for linting Oct 27, 2015
.travis.yml Trying to use apt from node-canvas Oct 27, 2015
LICENSE-MIT Initial transplant/tweaks from gmsmith Apr 28, 2013 Documented input image variations Nov 17, 2015
package.json Release 1.1.0 May 18, 2016

canvassmith Build status

node-canvas engine for spritesmith.


Due to dependance on node-canvas, you must install Cairo.

Instructions on how to do this are provided in the node-canvas wiki.

Additionally, you will need to install node-gyp.

npm install -g node-gyp

Getting Started

Install the module with: npm install canvassmith

// Load in our dependencies
var Canvassmith = require('canvassmith');

// Create a new engine
var canvassmith = new Canvassmith();

// Interpret some images from disk
canvassmith.createImages(['img1.jpg', 'img2.png'], function handleImages (err, imgs) {
  // If there was an error, throw it
  if (err) {
    throw err;

  // We recieve images in the same order they were given
  imgs[0].width; // 50 (pixels)
  imgs[0].height; // 100 (pixels)

  // Create a canvas that fits our images (200px wide, 300px tall)
  var canvas = canvassmith.createCanvas(200, 300);

  // Add the images to our canvas (at x=0, y=0 and x=50, y=100 respectively)
  canvas.addImage(imgs[0], 0, 0);
  canvas.addImage(imgs[1], 50, 100);

  // Export canvas to image
  var resultStream = canvas['export']({format: 'png'});
  resultStream; // Readable stream outputting PNG image of the canvas


This module was built to the specification for spritesmith engines.

Specification version: 2.0.0

engine.createImages(images, cb)

Our createImages methods supports the following types of images:

  • image String - Filepath to image
  • image Object - Vinyl object with buffer for image (uses buffer)
  • image Object - Vinyl object with stream for image (uses stream)
  • image Object - Vinyl object with null for image (reads buffer from provided filepath)


In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint using npm run lint and test via npm test.


Support this project and others by twolfson via gittip.

Support via Gittip


Copyright (c) 2013 Todd Wolfson

Licensed under the MIT license.