{"name":"spritesmith","version":"3.5.0","keywords":["sprite","spritesheet","css"],"author":{"url":"http://twolfson.com/","name":"Todd Wolfson","email":"todd@twolfson.com"},"license":"MIT","_id":"spritesmith@3.5.0","maintainers":[{"name":"twolfson","email":"todd@twolfson.com"}],"contributors":[{"name":"Alex Bain"}],"homepage":"https://github.com/twolfson/spritesmith","bugs":{"url":"https://github.com/twolfson/spritesmith/issues"},"dist":{"shasum":"a0d6ac5c4cf154f76601b1d6ec78575dd9b7c1d8","tarball":"http://registry-npm.ywwl.com/spritesmith/download/spritesmith-3.5.0.tgz","fileCount":42,"integrity":"sha512-TpOH8lDU+uLGxpgypI+QEQ18DtN3Bjk5AxLSurbrqidtzrOmFf5HbRaaqjlg+vmZxEz+z+j9gWbcTZGHL4uehw==","signatures":[{"sig":"MEQCIFtCJ7sOoBsp8NUEjIXe77wxv/4QM5TcYOF6KewEoRm/AiB7lB/n+2WcEW+RH2xN5Qm9M+IXbV5DzvXuIfKFz6vXtA==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":89446,"size":55077,"noattachment":false,"key":"/spritesmith/-/spritesmith-3.5.0.tgz"},"main":"src/smith.js","engines":{"node":">= 4.0.0"},"foundry":{"releaseCommands":["foundry-release-git","foundry-release-npm"]},"gitHead":"3bb5516add71bc17fe11f2112707208eed8a632a","scripts":{"lint":"eslint src/ src-test/ --max-warnings 0","test":"npm run precheck && mocha src-test/ --timeout 60000 --reporter dot && npm run lint","precheck":"eslint src/ src-test/"},"_npmUser":{"name":"twolfson","email":"todd@twolfson.com"},"repository":{"url":"git://github.com/twolfson/spritesmith.git","type":"git"},"_npmVersion":"8.11.0","description":"Utility that takes images and creates a spritesheet with JSON sprite data","directories":{},"_nodeVersion":"16.16.0","dependencies":{"layout":"~2.2.0","semver":"~5.7.2","through2":"~2.0.0","pixelsmith":"^2.3.0","concat-stream":"~1.5.1"},"_hasShrinkwrap":false,"devDependencies":{"mocha":"~10.7.3","vinyl":"~2.1.0","eslint":"~4.10.0","foundry":"~4.3.2","get-pixels":"~3.1.0","pixelmatch":"~4.0.2","canvassmith":"~1.7.0","phantomjssmith":"~1.0.0","foundry-release-git":"~2.0.2","foundry-release-npm":"~2.0.2","eslint-config-twolfson":"~1.0.0"},"_npmOperationalInternal":{"tmp":"tmp/spritesmith_3.5.0_1729665393651_0.4027620168410726","host":"s3://npm-registry-packages"},"readme":"# spritesmith [![Build status](https://travis-ci.org/twolfson/spritesmith.png?branch=master)](https://travis-ci.org/twolfson/spritesmith) [![Subscribe to newsletter](https://img.shields.io/badge/newsletter-subscribe-blue.svg)](http://eepurl.com/bD4qkf)\n\nConvert images into [spritesheets][] and coordinate maps.\n\n[spritesheets]: http://en.wikipedia.org/wiki/Sprite_%28computer_graphics%29#Sprites_by_CSS\n\n`spritesmith` is also available as:\n\n- [grunt plugin](https://github.com/twolfson/grunt-spritesmith)\n- [gulp plugin](https://github.com/twolfson/gulp.spritesmith)\n- [CLI utility](https://github.com/bevacqua/spritesmith-cli)\n\nA folder of icons processed by `spritesmith`:\n\n![Fork icon][fork-icon] ![+][]\n![GitHub icon][github-icon] ![+][]\n![Twitter icon][twitter-icon] ![=][]\n\n[fork-icon]: docs/fork.png\n[github-icon]: docs/github.png\n[twitter-icon]: docs/twitter.png\n[+]: docs/plus.png\n[=]: docs/equals.png\n\ngenerates a spritesheet:\n\n![spritesheet](docs/spritesheet.png)\n\nand a coordinate map:\n\n```js\n{\n  \"/home/todd/github/spritesmith/docs/fork.png\": {\n    \"x\": 0,\n    \"y\": 0,\n    \"width\": 32,\n    \"height\": 32\n  },\n  \"/home/todd/github/spritesmith/docs/github.png\": {\n    \"x\": 32,\n    \"y\": 0,\n    \"width\": 32,\n    \"height\": 32\n  },\n  // ...\n}\n```\n\n### Do you like `spritesmith`?\n[Support us via donations][support-us] or [spread word on Twitter][twitter]\n\n[support-us]: http://bit.ly/support-spritesmith-1\n[twitter]: https://twitter.com/intent/tweet?text=Spritesheets%20made%20easy%20via%20spritesmith&url=https%3A%2F%2Fgithub.com%2Ftwolfson%2Fspritesmith&via=twolfsn\n\n## Breaking changes in 2.0.0\nWe have moved from `result.image` being a binary string to it being a `Buffer`. This is to use more canonical conventions in Node.js.\n\nWe have moved from [spritesmith-engine-spec@1.1.0][] to [spritesmith-engine-spec@2.0.0][]. This means if you use an custom engine (e.g. `gmsmith`, `canvassmith`), then you will need to upgrade it.\n\n```bash\nnpm install my-engine-smith@latest --save-dev\n```\n\nBy upgrading the engine, we added support for [Vinyl][] objects via `src` as well as future-proof ourselves for forwarding streaming outputs.\n\n[spritesmith-engine-spec@1.1.0]: https://github.com/twolfson/spritesmith-engine-spec/tree/1.1.0\n[spritesmith-engine-spec@2.0.0]: https://github.com/twolfson/spritesmith-engine-spec/tree/2.0.0\n\n## Breaking changes in 3.0.0\nWe have updated our API to return streams for images. This required moving to a `constructor` and splitting apart image creation and processing.\n\nWe have maintained legacy support for `spritesmith` via `Spritesmith.run` which has an identical API to the `spritesmith` function in `spritesmith<3.0.0`.\n\n```js\n// Before\nvar spritesmith = require('spritesmith');\nspritesmith({src: sprites}, function handleResult (err, result) { /* ... */ });\n\n// After\nvar Spritesmith = require('spritesmith');\nSpritesmith.run({src: sprites}, function handleResult (err, result) { /* ... */ });\n```\n\n## Getting started\n`spritesmith` can be installed via npm: `npm install spritesmith`\n\n```js\n// Load in dependencies\nvar Spritesmith = require('spritesmith');\n\n// Generate our spritesheet\nvar sprites = ['fork.png', 'github.png', 'twitter.png'];\nSpritesmith.run({src: sprites}, function handleResult (err, result) {\n  result.image; // Buffer representation of image\n  result.coordinates; // Object mapping filename to {x, y, width, height} of image\n  result.properties; // Object with metadata about spritesheet {width, height}\n});\n```\n\n### Usage with streaming output\nWe support streaming output by breaking down `run` into 2 parts:\n\n```js\n// Load in dependencies\nvar Spritesmith = require('spritesmith');\n\n// Create a new spritesmith and process our images\nvar sprites = ['fork.png', 'github.png', 'twitter.png'];\nvar spritesmith = new Spritesmith();\nspritesmith.createImages(sprites, function handleImages (err, images) {\n  images[0].width; // Width of image\n  images[0].height; // Height of image\n\n  // Create our result\n  var result = spritesmith.processImages(images);\n  result.image; // Readable stream outputting image\n  result.coordinates; // Object mapping filename to {x, y, width, height} of image\n  result.properties; // Object with metadata about spritesheet {width, height}\n});\n```\n\n## Documentation\n`spritesmith` exports a `Spritesmith` constructor as its `module.exports`.\n\nIf you would like a faster build time or need to support an obscure image format, see `params.engine`.\n\nIf you would like to adjust how images are laid out, see `params.algorithm` and `params.algorithmOpts`.\n\n### `Spritesmith.run(params, callback)`\nHelper function that initializes a new `Spritesmith` instance, creates images, and processes them into a spritesheet\n\n- params `Object` - Container for parameters\n    - src `String[]|Object[]` - Same as `src` for `spritesmith.createImages`\n    - All other parameters accepted by `new Spritesmith` or `processImages` should be passed in here (e.g. `engine`, `algorithm`)\n- callback `Function` - Error-first function that receives compiled spritesheet and information\n    - `callback` should have signature `function (err, result)`\n    - err `Error|null` - If an error occurred, this will be it\n    - result `Object` - Container for result items\n        - Same signature as content returned by `spritesmith.processImages` (i.e. `{image, coordinates, properties}`)\n        - image `Buffer` - In-memory representation of image\n        - coordinates `Object` - Same as `coordinates` returned by `spritesmith.processImages`\n        - properties `Object` - Same as `properties` returned by `spritesmith.processImages`\n\n### `new Spritesmith(params)`\nConstructor for a new `Spritesmith` instance\n\n- params `Object` - Container for parameters\n    - engine `String|Object` - Optional engine override to use\n        - By default we use [`pixelsmith`][], a node-based `spritesmith` engine\n        - An example usage of `engine` can be found in the [Examples section](#engine)\n        - For more engine options, see the [Engines section](#engines)\n    - engineOpts `Object` - Options to pass through to engine for settings\n        - For example `phantomjssmith` accepts `timeout` via `{engineOpts: {timeout: 10000}}`\n        - See your engine's documentation for available options\n\n[`pixelsmith`]: https://github.com/twolfson/pixelsmith\n\n### `spritesmith.createImages(src, callback)`\nInterpret images via the `spritesmith` engine\n\n- src `String[]|Object[]` - Array of filepaths for images to include in spritesheet\n    - If a `String` is provided, then it's used as the image's filepath\n    - If an `Object` is provided, then it should be a [Vinyl][] object pointing to the source image\n        - Depending on the engine, we may/may not use the contents (e.g. `gmsmith` uses filepaths only)\n- callback `Function` - Error-first function that receives compiled spritesheet and map\n    - `callback` should have signature `function (err, images)`\n    - err `Error|null` - If an error occurred, this will be it\n    - images `Object[]` - Array of processed images\n        - Each `image` will be a proprietary object for the engine\n        - Each `image` will line up with the specification from [spritesmith-engine-spec][spec-createImages]\n        - image `Object` - Metadata container about corresponding input image at same index\n            - height `Number` - Height in pixels of corresponding input image at same index\n            - width `Number` - Width in pixels of corresponding input image at same index\n\n[Vinyl]: https://github.com/gulpjs/vinyl\n[spec-createImages]: https://github.com/twolfson/spritesmith-engine-spec/tree/2.0.0#enginecreateimagesimages-cb\n\n### `spritesheet.processImages(images, options)`\nPlace interpretted images on a canvas and export spritesheet\n\n- images `Object[]` - Images generated via `spritesmith.createImages`\n- options `Object` - Container for options\n    - padding `Number` - Padding to use between images\n        - For example if `2` is provided, then there will be a `2px` gap to the right and bottom between each image\n        - An example usage of `padding` can be found in the [Examples section](#padding)\n    - exportOpts `Mixed` - Options to pass through to engine for export\n        - For example `gmsmith` supports `quality` via `{exportOpts: {quality: 75}}`\n        - See your engine's documentation for available options\n    - algorithm `String` - Optional algorithm to pack images with\n        - By default we use `binary-tree` which packs images as efficiently as possible\n        - An example usage of `algorithm` can be found in the [Examples section](#algorithm)\n        - For more algorithm options, see the [Algorithms section](#algorithms)\n    - algorithmOpts `Object` - Optional algorithm options to pass through to algorithm for layout\n        - For example `top-down` supports ignoring sorting via `{algorithmOpts: {sort: false}}`\n        - See your algorithm's documentation for available options\n            - https://github.com/twolfson/layout#algorithms\n\n**Returns:**\n\n- result `Object` - Container for result information\n    - image `ReadableStream` - [Readable stream][] outputting generated image contents\n    - coordinates `Object` - Map from filepath to coordinate information between original sprite and spritesheet\n        - `filepath` will be the same as provided in `params.src`\n        - [filepath] `Object` - Container for coordinate information\n            - For those keeping track, this is `result.coordinates[filepath]`\n            - x `Number` - Horizontal position of top-left corner of original sprite on spritesheet\n            - y `Number` - Vertical position of top-left corner of original sprite on spritesheet\n            - width `Number` - Width of original sprite\n            - height `Number` - Height of original sprite\n    - properties `Object` - Container for information about spritesheet\n        - width `Number` - Width of the spritesheet\n        - height `Number` - Height of the spritesheet\n\n[Readable stream]: https://nodejs.org/api/stream.html#stream_class_stream_readable\n\n### Algorithms\nImages can be laid out in different fashions depending on the algorithm. We use [`layout`][] to provide you as many options as possible. At the time of writing, here are your options for `params.algorithm`:\n\n[`layout`]: https://github.com/twolfson/layout\n\n|         `top-down`        |          `left-right`         |         `diagonal`        |           `alt-diagonal`          |          `binary-tree`          |\n|---------------------------|-------------------------------|---------------------------|-----------------------------------|---------------------------------|\n| ![top-down][top-down-img] | ![left-right][left-right-img] | ![diagonal][diagonal-img] | ![alt-diagonal][alt-diagonal-img] | ![binary-tree][binary-tree-img] |\n\n[top-down-img]: https://raw.githubusercontent.com/twolfson/layout/2.0.2/docs/top-down.png\n[left-right-img]: https://raw.githubusercontent.com/twolfson/layout/2.0.2/docs/left-right.png\n[diagonal-img]: https://raw.githubusercontent.com/twolfson/layout/2.0.2/docs/diagonal.png\n[alt-diagonal-img]: https://raw.githubusercontent.com/twolfson/layout/2.0.2/docs/alt-diagonal.png\n[binary-tree-img]: https://raw.githubusercontent.com/twolfson/layout/2.0.2/docs/binary-tree.png\n\nMore information can be found in the [`layout`][] documentation:\n\nhttps://github.com/twolfson/layout\n\n### Engines\nAn engine can greatly improve the speed of your build (e.g. `canvassmith`) or support obscure image formats (e.g. `gmsmith`).\n\nAll `spritesmith` engines adhere to a common specification:\n\nhttps://github.com/twolfson/spritesmith-engine-spec\n\nThis repository adheres to specification version: **2.0.0**\n\nBelow is a list of known engines with their tradeoffs:\n\n#### pixelsmith\n[`pixelsmith`][] is a `node` based engine that runs on top of [`get-pixels`][] and [`save-pixels`][].\n\n[`get-pixels`]: https://github.com/mikolalysenko/get-pixels\n[`save-pixels`]: https://github.com/mikolalysenko/save-pixels\n\n**Key differences:** Doesn't support uncommon image formats (e.g. `tiff`) and not as fast as a compiled library (e.g. `canvassmith`).\n\n#### phantomjssmith\n[`phantomjssmith`][] is a [phantomjs][] based engine. It was originally built to provide cross-platform compatibility but has since been succeeded by [`pixelsmith`][].\n\n**Requirements:** [phantomjs][] must be installed on your machine and on your `PATH` environment variable. Visit [the phantomjs website][phantomjs] for installation instructions.\n\n**Key differences:** `phantomjs` is cross-platform and supports all image formats.\n\n[`phantomjssmith`]: https://github.com/twolfson/phantomjssmith\n[phantomjs]: http://phantomjs.org/\n\n#### canvassmith\n[`canvassmith`][] is a [node-canvas][] based engine that runs on top of [Cairo][].\n\n**Requirements:** [Cairo][] and [node-gyp][] must be installed on your machine.\n\nInstructions on how to install [Cairo][] are provided in the [node-canvas wiki][].\n\n[node-gyp][] should be installed via `npm`:\n\n```bash\nnpm install -g node-gyp\n```\n\n**Key differences:** `canvas` has the best performance (useful for over 100 sprites). However, it is `UNIX` only.\n\n[`canvassmith`]: https://github.com/twolfson/canvassmith\n[node-canvas]: https://github.com/learnboost/node-canvas\n[Cairo]: http://cairographics.org/\n[node-canvas wiki]: (https://github.com/LearnBoost/node-canvas/wiki/_pages\n[node-gyp]: https://github.com/TooTallNate/node-gyp/\n\n#### gmsmith\n[`gmsmith`][] is a [`gm`][] based engine that runs on top of either [Graphics Magick][] or [Image Magick][].\n\n**Requirements:** Either [Graphics Magick][] or [Image Magick][] must be installed on your machine.\n\nFor the best results, install from the site rather than through a package manager (e.g. `apt-get`). This avoids potential transparency issues which have been reported.\n\n[Image Magick][] is implicitly discovered. However, you can explicitly use it via `engineOpts`\n\n```js\n{\n  engineOpts: {\n    imagemagick: true\n  }\n}\n```\n\n**Key differences:** `gmsmith` allows for configuring image quality whereas others do not.\n\n[`gmsmith`]: https://github.com/twolfson/gmsmith\n[`gm`]: https://github.com/aheckmann/gm\n[Graphics Magick]: http://www.graphicsmagick.org/\n[Image Magick]: http://imagemagick.org/\n\n## Examples\n### Algorithm\nThis is an example of using a custom layout via the `alt-diagonal` algorithm.\n\n```js\n// Load in dependencies\nvar fs = require('fs');\nvar Spritesmith = require('spritesmith');\n\n// Generate our spritesheet\nSpritesmith.run({\n  src: [\n    __dirname + '/fork.png',\n    __dirname + '/github.png',\n    __dirname + '/twitter.png'\n  ],\n  algorithm: 'alt-diagonal'\n}, function handleResult (err, result) {\n  // If there was an error, throw it\n  if (err) {\n    throw err;\n  }\n\n  // Output the image\n  fs.writeFileSync(__dirname + '/alt-diagonal.png', result.image);\n  result.coordinates, result.properties; // Coordinates and properties\n});\n```\n\n**Result:**\n\n![alt-diagonal spritesheet](docs/alt-diagonal.png)\n\n### Engine\nThis is an example of using a custom engine (`canvassmith` in this case).\n\n```js\n// Inside package.json\n{\n    \"dependencies\": {\n        \"canvassmith\": \"~0.2.4\"\n    }\n}\n```\n\n```js\n// In our script\n// Load in dependencies\nvar fs = require('fs');\nvar Spritesmith = require('spritesmith');\n\n// Generate our spritesheet\nSpritesmith.run({\n  src: [\n    __dirname + '/fork.png',\n    __dirname + '/github.png',\n    __dirname + '/twitter.png'\n  ],\n  engine: require('canvassmith')\n}, function handleResult (err, result) {\n  // If there was an error, throw it\n  if (err) {\n    throw err;\n  }\n\n  // Output the image\n  fs.writeFileSync(__dirname + '/canvassmith.png', result.image);\n  result.coordinates, result.properties; // Coordinates and properties\n});\n```\n\n**Result:**\n\n![canvassmith spritesheet](docs/canvassmith.png)\n\n### Padding\nThis is an example of adding padding between images.\n\n```js\n// Load in dependencies\nvar fs = require('fs');\nvar Spritesmith = require('spritesmith');\n\n// Generate our spritesheet\nSpritesmith.run({\n  src: [\n    __dirname + '/fork.png',\n    __dirname + '/github.png',\n    __dirname + '/twitter.png'\n  ],\n  padding: 20 // Exaggerated for visibility, normally 1 or 2\n}, function handleResult (err, result) {\n  // If there was an error, throw it\n  if (err) {\n    throw err;\n  }\n\n  // Output the image\n  fs.writeFileSync(__dirname + '/padding.png', result.image);\n  result.coordinates, result.properties; // Coordinates and properties\n});\n```\n\n**Result:**\n\n![padding spritesheet](docs/padding.png)\n\n## Contributing\nIn 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`.\n\n## Attribution\n[GitHub][github-icon] and [Twitter][twitter-icon] icons were taken from [Alex Peattie's JustVector Social Icons][justvector].\n\n[Fork][noun-fork-icon] designed by [P.J. Onori][onori] from The Noun Project\n\n[Plus][+] and [Equals][=] icons were built using the [Ubuntu Light typeface][ubuntu-light].\n\n[justvector]: http://alexpeattie.com/projects/justvector_icons/\n[noun-fork-icon]: http://thenounproject.com/noun/fork/#icon-No2813\n[onori]: http://thenounproject.com/somerandomdude\n[ubuntu-light]: http://font.ubuntu.com/\n\n## License\nCopyright (c) 2012 Todd Wolfson\n\nLicensed under the MIT license.\n","publish_time":1729665393948,"_cnpm_publish_time":1729665393948,"dist-tags":{"latest":"3.5.1"}}