canvassmith
node-canvas engine for spritesmith
Last updated 9 years ago by twolfson .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install canvassmith 
SYNC missed versions from official npm registry.

canvassmith Build status

node-canvas engine for spritesmith.

Requirements

By default, binaries for macOS, Linux and Windows will be downloaded. But if you don't have a supported OS or processor architecture the module will be compiled on your system. This requires several dependencies from node-canvas, you must install Cairo and Pango.

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
});

Documentation

This module was built to the specification for spritesmith engines.

Specification version: 2.0.0

https://github.com/twolfson/spritesmith-engine-spec/tree/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)

Contributing

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.

Donating

Support this project and others by twolfson via donations.

http://twolfson.com/support-me

License

Copyright (c) 2013 Todd Wolfson

Licensed under the MIT license.

Current Tags

  • 1.7.0                                ...           latest (3 years ago)

29 Versions

  • 1.7.0                                ...           3 years ago
  • 1.6.0                                ...           4 years ago
  • 1.5.0                                ...           5 years ago
  • 1.4.1                                ...           6 years ago
  • 1.4.0                                ...           6 years ago
  • 1.3.0                                ...           7 years ago
  • 1.2.1                                ...           7 years ago
  • 1.2.0                                ...           7 years ago
  • 1.1.0                                ...           8 years ago
  • 1.0.0                                ...           9 years ago
  • 0.4.4                                ...           9 years ago
  • 0.4.3                                ...           9 years ago
  • 0.4.2                                ...           9 years ago
  • 0.4.1                                ...           9 years ago
  • 0.4.0                                ...           9 years ago
  • 0.3.2                                ...           9 years ago
  • 0.3.1                                ...           9 years ago
  • 0.3.0                                ...           9 years ago
  • 0.2.5                                ...           9 years ago
  • 0.2.4                                ...           10 years ago
  • 0.2.3                                ...           10 years ago
  • 0.2.2                                ...           10 years ago
  • 0.2.1                                ...           11 years ago
  • 0.2.0                                ...           11 years ago
  • 0.1.5                                ...           11 years ago
  • 0.1.4                                ...           11 years ago
  • 0.1.3                                ...           11 years ago
  • 0.1.2                                ...           11 years ago
  • 0.1.0                                ...           12 years ago
Maintainers (1)
Downloads
Total 23
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (8)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE