phantomjssmith

PhantomJS engine for spritesmith

npm install phantomjssmith
274 downloads in the last day
1 484 downloads in the last week
7 062 downloads in the last month

phantomjssmith Build status

PhantomJS engine for spritesmith.

Requirements

This depends on having phantomjs installed on your machine. For installation instructions, visit the website. This module has been tested against 1.9.0.

Getting Started

Install the module with: npm install phantomjssmith

// Convert images into phantomjssmith objects
var images = ['img1.jpg', 'img2.png'];
phantomjssmith.createImages(this.images, function handleImages (err, imgs) {
  // Create a canvas to draw onto (200 pixels wide, 300 pixels tall)
  phantomjssmith.createCanvas(200, 200, function (err, canvas) {
    // Add each image at a specific location (upper left corner = {x, y})
    var coordinatesArr = [{x: 0, y: 0}, {x: 50, y: 50}];
    imgs.forEach(function (img, i) {
      var coordinates = coordinatesArr[i];
      canvas.addImage(img, coordinates.x, coordinates.y);
    }, canvas);

    // Export canvas to image
    canvas['export']({format: 'png'}, function (err, result) {
      result; // Binary string representing a PNG image of the canvas
    });
  });
});

Documentation

This module was built to the specification for all spritesmith modules.

https://github.com/twolfson/spritesmith-engine-test

canvas'export'

These are options specific phantomjssmith

  • options Object
    • timeout Number - Milliseconds to wait until automatically terminating PhantomJS script. By default, this is 10000 (10 seconds).
    • format String - Output image format to callback with. Currently, only png is available.

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 grunt and test via npm test.

Donating

Support this project and others by twolfson via gittip.

Support via Gittip

License

Copyright (c) 2013 Todd Wolfson

Licensed under the MIT license.

npm loves you