包详细信息

gmsmith

twolfson16.2kMIT1.4.0

GM engine for spritesmith

spritesmith, image, spritesmith-engine

自述文件

gmsmith Build status

GM engine for spritesmith.

Requirements

gmsmith depends on gm which depends on GraphicsMagick.

I have found it is best to install from the site rather than through a package manager (e.g. apt-get) to get the latest as well as without transparency issues.

This module has been developed and tested against 1.3.17.

Alertnatively, you can use ImageMagick which is implicitly discovered if gm is not installed. http://www.imagemagick.org/script/index.php

Getting Started

Install the module with: npm install gmsmith

// Load in our dependencies
var Gmsmith = require('gmsmith');

// Create a new engine
var gmsmith = new Gmsmith();

// Interpret some images from disk
gmsmith.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 = gmsmith.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

new Engine(options)

This is also known as new Gmsmith.

Our Engine constructor provides support for the following options:

engine.createImages(images, cb)

Our createImages methods supports the following types of images:

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

We accept but don't fully support the following types of images:

  • image Object - Vinyl object with buffer for image (ignores contents, uses provided filepath)
  • image Object - Vinyl object with stream for image (ignores contents, uses provided filepath)

canvas.export(options)

Our export method provides support for the following options:

  • options Object
    • format String - Output image format to callback with. Currently, png and jpeg are available.
    • quality Number - Quality of output image on a scale 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 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.

更新日志

gmsmith changelog

1.4.0 - Upgraded dependencies via @striezel in #19

1.3.0 - Upgraded dependencies via @striezel in #17

1.2.0 - Upgraded to gm@1.23.1 to fix vulnerabilities via @danez in #15

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

1.1.5 - Corrected CHANGELOG

1.1.4 - Upgraded to spritesmith-engine-test@5.0.0 to verify Vinyl@2 support

1.1.3 - Replaced Gittip with support me page

1.1.2 - Added fallback for options via @@marekventur in #12

1.1.1 - Added format documentation to README via @marekventur in #11

1.1.0 - Updated dependencies via @danez in #9. Fixes #7

1.0.1 - Updated license in package.json to SPDX format via @danez in #8

1.0.0 - Upgraded to spritesmith-engine-spec@2.0.0

0.6.4 - Added specVersion to repository and spritesmith-engine to keywords

0.6.3 - Fixed failing Travis CI tests

0.6.2 - Cleaned up README and updated spec link to spritesmith-engine-spec

0.6.1 - Moved to spritesmith-engine-test@3.0.0 to clean up technical debt

0.6.0 - Cleaned up technical debt (e.g. writing to disk, disjoint yet related parts of code)

0.5.4 - Removed grunt as a devDependency

0.5.3 - Added twolfson-style for linting

0.5.2 - Updated supported node versions to >= 0.10.0

0.5.1 - Added foundry for release

0.5.0 - Upgraded gm and temporary dependencies to add node@0.12 and iojs support

0.4.5 - Added documentation for quality

0.4.4 - Upgraded to spritesmith-engine-test@2.0.0 and moved to mocha

0.4.3 - Upgraded npm inside Travis CI to fix node@0.8 issues

0.4.2 - Repaired legacy logic that caused 0.4.0 patch to fail whenever .set was called

0.4.1 - Re-enabling Travis CI tests for all supported node versions

0.4.0 - Implicitly discover imagemagick when gm doesn't exist and imagemagick flag is unspecified

0.3.0 - Added imagemagick to test suite and corrected preinstall for package.json

0.2.3 - Removed postinstall piping to allow cross-platform

0.2.2 - Integrated Travis CI

0.2.1 - Upgraded doubleshot and skipping imagemagick tests for approachability

0.2.0 - Added get/set support and imagemagick flag setting

0.1.3 - See git log