Detalhes do pacote

pixelsmith

twolfson221.5k2.6.0

Node based engine for spritesmith

spritesmith, image, spritesmith-engine

readme (leia-me)

pixelsmith Build Status

Node based engine for spritesmith built of top of get-pixels and save-pixels.

This can be used for constructing a canvas, placing images on it, and extracting the result image.

Getting Started

Install the module with: npm install pixelsmith

// Load in our dependencies
var Pixelsmith = require('pixelsmith');

// Create a new engine
var pixelsmith = new Pixelsmith();

// Interpret some images from disk
pixelsmith.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 = pixelsmith.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(options)

Our engine constructor supports the following options:

  • options Object - Optional container for various settings
    • concurrentFileLimit Number - Amount of files to load concurrently via createImages
      • May be useful if bumping into EMFILE (file descriptor limit)

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)

canvas.export(options)

Our export method provides support for the following options:

  • options Object
    • background Number[] - rgba array of value for background
      • By default, the background is [0, 0, 0, 0] (transparent black)
      • [0] - Red value for background
        • Can range from 0 to 255
      • [1] - Green value for background
        • Can range from 0 to 255
      • [2] - Blue value for background
        • Can range from 0 to 255
      • [3] - Alpha/transparency value for background
        • Can range from 0 to 255
    • quality Number - Optional quality percentage for JPEG images
      • This value can range from 0 to 100

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

Donating

Support this project and others by twolfson via donations.

http://twolfson.com/support-me

Unlicense

As of Nov 24 2014, Todd Wolfson has released this repository and its contents to the public domain.

It has been released under the UNLICENSE.

changelog (log de mudanças)

pixelsmith changelog

2.6.0 - Upgraded async via @xfix in #21 and moved to Node.js>=12 to fix Travis CI

2.5.0 - Added support for options.concurrentFileLimit. Fixes #20

2.4.1 - Removed accidental double callback from getPixels

2.4.0 - Added filepath info to when invalid file extension loaded. Fixes #16

2.3.0 - Removed ndarray-fill to fix npm audit vulnerability via @dawidgarus in #17

2.2.2 - Moved to Node.js>=8 to fix Travis CI

2.2.1 - Moved to Node.js>=4 to fix Travis CI

2.2.0 - Added support for Vinyl@2

2.1.3 - Replaced Gratipay with support me page

2.1.2 - Added file size check. Fixes gulp.spritesmith#131

2.1.1 - Upgraded to get-pixels@3.3.0 via @BS-Harou in #9

2.1.0 - Added quality support for JPEGs

2.0.1 - Upgraded to save-pixels@2.3.0 to resolve pngjs2 deprecation warning. Fixes #6

2.0.0 - Upgraded to spritesmith-engine-spec@2.0.0

1.3.4 - Added specVersion support and spritesmith-engine keyword

1.3.3 - Updated documentation to be a little cleaner and link to spritesmith-engine-spec

1.3.2 - Upgraded to spritesmith-engine-test@3.0.0 to clean up technical debt

1.3.1 - Removed bad require

1.3.0 - Cleaned up technical debt (e.g. YAGNI on exporters)

1.2.2 - Updated supported node versions to >= 0.10.0

1.2.1 - Added foundry for release

1.2.0 - Upgraded to get-pixels@3.2.3 to add better PNG support

1.1.2 - Moved from deprecated licenses key to license in package.json

1.1.1 - Fixed example in README via @tmcw in #3

1.1.0 - Added support for custom background. Fixes twolfson/gulp.spritesmith#33

1.0.0 - Initial fork from pngsmith@0.1.3