{"id":13671826,"url":"https://github.com/twolfson/gulp.spritesmith","last_synced_at":"2025-05-14T22:09:06.743Z","repository":{"id":13979399,"uuid":"16680216","full_name":"twolfson/gulp.spritesmith","owner":"twolfson","description":"Convert a set of images into a spritesheet and CSS variables via gulp","archived":false,"fork":false,"pushed_at":"2024-07-04T02:34:56.000Z","size":577,"stargazers_count":1074,"open_issues_count":2,"forks_count":81,"subscribers_count":31,"default_branch":"master","last_synced_at":"2025-05-09T13:59:07.452Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twolfson.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":"https://twolfson.com/support-me"}},"created_at":"2014-02-10T00:54:49.000Z","updated_at":"2025-04-17T17:04:06.000Z","dependencies_parsed_at":"2024-09-30T19:20:53.936Z","dependency_job_id":"18bb5a1c-f817-40ae-9cd2-74d1ca9f9622","html_url":"https://github.com/twolfson/gulp.spritesmith","commit_stats":{"total_commits":395,"total_committers":6,"mean_commits":65.83333333333333,"dds":0.02278481012658229,"last_synced_commit":"23e93919e9dda9cd8d3457bc3f29947caa0fde0c"},"previous_names":[],"tags_count":79,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twolfson%2Fgulp.spritesmith","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twolfson%2Fgulp.spritesmith/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twolfson%2Fgulp.spritesmith/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twolfson%2Fgulp.spritesmith/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twolfson","download_url":"https://codeload.github.com/twolfson/gulp.spritesmith/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254235701,"owners_count":22036964,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T09:01:19.699Z","updated_at":"2025-05-14T22:09:01.724Z","avatar_url":"https://github.com/twolfson.png","language":"JavaScript","readme":"# gulp.spritesmith [![Build status](https://travis-ci.org/twolfson/gulp.spritesmith.svg?branch=master)](https://travis-ci.org/twolfson/gulp.spritesmith) [![Subscribe to newsletter](https://img.shields.io/badge/newsletter-subscribe-blue.svg)](http://eepurl.com/bD4qkf)\n\nConvert a set of images into a spritesheet and CSS variables via [gulp][]\n\nThis is the official port of [grunt-spritesmith][], the [grunt][] equivalent of a wrapper around [spritesmith][].\n\n[gulp]: http://gulpjs.com/\n[grunt-spritesmith]: https://github.com/Ensighten/grunt-spritesmith\n[grunt]: http://gruntjs.com/\n[spritesmith]: https://github.com/Ensighten/spritesmith\n\n![Example input/output](docs/example.png)\n\nAlternative output formats include [SASS, Stylus, LESS, and JSON][css-formats].\n\n[css-formats]: #spritesmithparams\n\n### Retina support\nAs of `gulp.spritesmith@3.5.0`, retina spritesheets/templates are supported. See the [Retina parameters section](#retina-parameters) for more information.\n\n### Do you like `gulp.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=CSS%20sprites%20made%20easy%20via%20gulp.spritesmith\u0026url=https%3A%2F%2Fgithub.com%2Ftwolfson%2Fgulp.spritesmith\u0026via=twolfsn\n\n## Breaking changes in 4.0.0\nWe are normalizing sprite variables even further to convert any non-alphanumeric/non-dash/non-underscore character to a delimiter character (e.g. `-`). This allows us to support naming retina sprites with `@2x` suffixes, to prevent regressions like [grunt-spritesmith#137][].\n\n[grunt-spritesmith#137]: https://github.com/Ensighten/grunt-spritesmith/issues/137\n\n## Breaking changes in 5.0.0\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\nThis is enables us to use streaming outputs from engines in a future release.\n\nAdditionally, we have added support for `buffer` and `stream` content for in-memory engines (e.g. `pixelsmith`, `canvassmith`) which resolves [#53][].\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[#53]: https://github.com/twolfson/gulp.spritesmith/issues/53\n\n## Breaking changes in 6.0.0\nWe have completed our integration with streaming outputs from engines. As a result, [Vinyl][] `img` files will have `stream` contents which were previously buffers.\n\nIf your `img` pipeline requires `Buffer` contents, then this can be remedied via [vinyl-buffer][]:\n\n```js\n// Throws error due to not supporting streams\nspriteData.img.pipe(imagemin());\n\n// Back to operational\nvar buffer = require('vinyl-buffer');\nspriteData.img.pipe(buffer()).pipe(imagemin());\n```\n\n[vinyl-buffer]: https://github.com/hughsk/vinyl-buffer\n\n## Note for Gulp 5.0.0 upgrades\nGulp 5.0.0 introduced default encodings for `src` and `dest` streams of `utf8`.\n\nSince `gulp.spritesmith` inputs and outputs images, we need to set `{encoding: false}` for the image `.src()` and `.dest()` streams.\n\nSee \"[Getting Started](#getting-started)\" for an hands-on example.\n\n## Getting Started\nInstall the module with: `npm install gulp.spritesmith`\n\n```js\nvar gulp = require('gulp');\nvar spritesmith = require('gulp.spritesmith');\n\ngulp.task('sprite', function () {\n  var spriteData = gulp.src('images/*.png', {encoding: false}).pipe(spritesmith({\n    imgName: 'sprite.png',\n    cssName: 'sprite.css'\n  }));\n  return spriteData.pipe(gulp.dest('path/to/output/', {encoding: false}));\n});\n```\n\n### Continuing the pipeline\nIn addition to the `spriteData` stream, we offer individual streams for images and CSS. This allows for image optimization and CSS minification.\n\n```js\nvar gulp = require('gulp');\nvar buffer = require('vinyl-buffer');\nvar csso = require('gulp-csso');\nvar imagemin = require('gulp-imagemin');\nvar merge = require('merge-stream');\n\nvar spritesmith = require('gulp.spritesmith');\n\ngulp.task('sprite', function () {\n  // Generate our spritesheet\n  var spriteData = gulp.src('images/*.png', {encoding: false}).pipe(spritesmith({\n    imgName: 'sprite.png',\n    cssName: 'sprite.css'\n  }));\n\n  // Pipe image stream through image optimizer and onto disk\n  var imgStream = spriteData.img\n    // DEV: We must buffer our stream into a Buffer for `imagemin`\n    .pipe(buffer())\n    .pipe(imagemin())\n    .pipe(gulp.dest('path/to/image/folder/', {encoding: false}));\n\n  // Pipe CSS stream through CSS optimizer and onto disk\n  var cssStream = spriteData.css\n    .pipe(csso())\n    .pipe(gulp.dest('path/to/css/folder/'));\n\n  // Return a merged stream to handle both `end` events\n  return merge(imgStream, cssStream);\n});\n```\n\n## Documentation\n`gulp.spritesmith` presents the `spritesmith` function as its `module.exports`.\n\n### `spritesmith(params)`\n[gulp][] plugin that returns a [transform stream][] with 2 [readable stream][] properties.\n\nThe input/output streams interact with [Vinyl][] objects which are [gulp's][gulp] format of choice.\n\n[transform stream]: http://nodejs.org/api/stream.html#stream_class_stream_transform\n[readable stream]: http://nodejs.org/api/stream.html#stream_class_stream_readable\n[Vinyl]: https://github.com/gulpjs/vinyl\n\n- params `Object` - Container for `gulp.spritesmith` parameters\n    - imgName `String` - Filename to save image as\n        - Supported image extensions are `.png` and `.jpg/jpeg` (limited to specfic engines)\n        - Image format can be overridden via `imgOpts.format`\n    - cssName `String` - Filename to save CSS as\n        - Supported CSS extensions are `.css` (CSS), `.sass` ([SASS][]), `.scss` ([SCSS][]), `.less` ([LESS][]), `.styl/.stylus` ([Stylus][]), and `.json` ([JSON][])\n        - CSS format can be overridden via `cssFormat`\n    - imgPath `String` - Optional path to use in CSS referring to image location\n    - padding `Number` - Optional amount of pixels to include between images\n        - By default we use no padding between images (`0`)\n        - An example usage can be found in the [Examples section](#padding)\n    - algorithm `String` - Optional method for how to pack images\n        - By default we use `binary-tree`, which packs images as efficiently as possible\n        - An example usage can be found in the [Examples section](#algorithm)\n        - More information can be found in the [Algorithms section](#algorithms)\n    - algorithmOpts `Object` - Options to pass through to algorithm\n        - For example we can skip sorting in some algorithms via `{algorithmOpts: {sort: false}}`\n          - This is useful for sprite animations\n      - See your algorithm's documentation for available options\n          - https://github.com/twolfson/layout#algorithms\n    - engine `String` - Optional image generating engine to use\n        - By default we use `pixelsmith`, a `node` based engine that supports all common image formats\n        - Alternative engines must be installed via `npm install`\n        - An example usage can be found in the [Examples section](#engine)\n        - More information can be found in 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    - imgOpts `Object` - Options to pass through to engine uring export\n        - For example `gmsmith` supports `quality` via `{imgOpts: {quality: 75}}`\n        - See your engine's documentation for available options\n    - cssFormat `String` - CSS format to use\n        - By default this is the format inferred by `cssName's` extension\n            - For example `.styl -\u003e stylus`\n        - For more format options, see our formatting library\n            - https://github.com/twolfson/spritesheet-templates#templates\n    - cssTemplate `String|Function` - CSS template to use for rendering output CSS\n        - This overrides `cssFormat`\n        - If a `String` is provided, it must be a path to a [handlebars][] template\n            - An example usage can be found in the [Examples section](#handlebars-template)\n        - If a `Function` is provided, it must have a signature of `function (data)`\n            - An example usage can be found in the [Examples section](#template-function)\n        - For more templating information, see the [Templating section](#templating)\n    - cssHandlebarsHelpers `Object` - Container for helpers to register to [handlebars][] for our template\n        - Each key-value pair is the name of a [handlebars][] helper corresponding to its function\n        - For example, `{half: function (num) { return num/2; }` will add a [handlebars][] helper that halves numbers\n    - cssVarMap `Function` - Mapping function for each filename to CSS variable\n        - For more information, see [Variable mapping](#variable-mapping)\n    - cssSpritesheetName `String` - Name to use for spritesheet related variables in preprocessor templates\n    - cssOpts `Object` - Options to pass through to templater\n        - For example `{cssOpts: {functions: false}}` skips output of mixins\n        - See your template's documentation for available options\n            - https://github.com/twolfson/spritesheet-templates#templates\n\n[SASS]: http://sass-lang.com/\n[SCSS]: http://sass-lang.com/\n[sass-maps]: http://sass-lang.com/documentation/file.SASS_REFERENCE.html#maps\n[LESS]: http://lesscss.org/\n[Stylus]: http://learnboost.github.com/stylus/\n[JSON]: http://json.org/\n[handlebars]: http://handlebarsjs.com/\n\n**Returns**:\n- spriteData [`stream.Transform`][transform stream] - Stream that outputs image and CSS as [Vinyl][] objects\n- spriteData.img [`stream.Readable`][readable stream] - Stream for image output as a [Vinyl][] object\n    - `contents` will be a `Stream`\n- spriteData.css [`stream.Readable`][readable stream] - Stream for CSS output as a [Vinyl][] object\n    - `contents` will be a `Buffer`\n\n### Retina parameters\n`gulp.spritesmith` supports retina spritesheet generation via `retinaSrcFilter` and `retinaImgName`. If at least one of these is provided, then we will expect the other and enable retina spritesheet generation.\n\nRepeated parameters have the same properties as above but are repeated for clarity with respect to retina spritesheets.\n\nAn example retina spritesheet setup can be found in the [Examples section](#retina-spritesheet).\n\nWe receive both normal and retina sprites from the same `gulp.src` so please include them in your original glob. (e.g. `*.png` should include `icon-home.png` and `icon-home@2x.png`).\n\n**We strongly encourage using the `@2x` suffix for retina sprites over `-retina` or `-2x`. There are known ordering issues caused when sharing a `-` delimiter between sprite names and the retina suffix (see [grunt-spritesmith#137][]).**\n\n- params `Object` - Container for `gulp.spritesmith` parameters\n    - retinaSrcFilter `String|String[]` - Filepaths to filter out from incoming stream for our retina spritesheet\n        - This can be a glob as with `src` (e.g. `sprite/*@2x.png`)\n        - The path/glob used should line up with `gulp.src` (e.g. `gulp.src('sprite/*.png', {encoding: false})`, `retinaSrcFilter: 'sprite/*@2x.png'`)\n        - For example `sprites/*@2x.png` will filter out `sprite1@2x.png` for a separate retina spritesheet\n            - Under the hood, we will group `sprite1.png` and `sprite1@2x.png` as a group of normal/retina sprites\n    - retinaImgName `String` - Filename to save retina spritesheet as\n    - retinaImgPath `String` - Optional path to use in CSS referring to image location\n        - For example `../sprite@2x.png`  will yield CSS with:\n            - `background-image: url(../sprite@2x.png);`\n    - padding `Number` - Padding to place to right and bottom between sprites\n        - By default there is no padding\n        - In retina spritesheets, this number will be doubled to maintain perspective\n    - cssFormat - CSS format to use\n        - By default this is the format inferred by `cssName's` extension\n            - For example `.styl -\u003e stylus_retina`\n        - For more format options, see our formatting library\n            - https://github.com/twolfson/spritesheet-templates#retina-templates\n    - cssVarMap `Function` - Mapping function for each filename to CSS variable\n        - This will run through normal and retina spritesheets\n        - The name used for normal sprites dictates the group name for retina group variables (e.g. `$icon-home` will have group `$icon-home-group`)\n        - For more information, see [Variable mapping](#variable-mapping)\n    - cssRetinaSpritesheetName `String` - Name to use for retina spritesheet related variables in preprocessor templates\n    - cssRetinaGroupsName `String` - Name to use for retina groups related variables in preprocessor templates\n\n**Returns**:\n- spriteData [`stream.Transform`][transform stream] - Stream that outputs image, retina image, and CSS as [Vinyl][] objects\n- spriteData.img [`stream.Readable`][readable stream] - Stream for image outputs (normal and retina) as a [Vinyl][] object\n    - `contents` will be a `Stream`\n- spriteData.css [`stream.Readable`][readable stream] - Stream for retina CSS output as a [Vinyl][] object\n    - `contents` will be a `Buffer`\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 `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### Templating\nThe `cssTemplate` option allows for using a custom template. An example template can be found at:\n\nhttps://github.com/twolfson/spritesheet-templates/blob/9.3.1/lib/templates/stylus.template.handlebars\n\nThe parameters passed into your template are known as `data`. We add some normalized properties via [`spritesheet-templates`][] for your convenience.\n\n- data `Object` Container for parameters\n    - sprites `Object[]` - Array of sprite information\n        - name `String` - Name of the sprite file (sans extension)\n        - x `Number` - Horizontal position of sprite's left edge in spritesheet\n        - y `Number` - Vertical position of sprite's top edge in spritesheet\n        - width `Number` - Width of sprite\n        - height `Number` - Height of sprite\n        - total_width `Number` - Width of entire spritesheet\n        - total_height `Number` - Height of entire spritesheet\n        - image `String` - Relative URL path from CSS to spritesheet\n        - escaped_image `String` - URL encoded `image`\n        - source_image `String` - Path to the original sprite file\n        - offset_x `Number` - Negative value of `x`. Useful to `background-position`\n        - offset_y `Number` - Negative value of `y`. Useful to `background-position`\n        - px `Object` - Container for numeric values including `px`\n            - x `String` - `x` suffixed with `px`\n            - y `String` - `y` suffixed with `px`\n            - width `String` - `width` suffixed with `px`\n            - height `String` - `height` suffixed with `px`\n            - total_width `String` - `total_width` suffixed with `px`\n            - total_height `String` - `total_height` suffixed with `px`\n            - offset_x `String` - `offset_x` suffixed with `px`\n            - offset_y `String` - `offset_y` suffixed with `px`\n    - spritesheet `Object` - Information about spritesheet\n        - width `Number` - Width of entire spritesheet\n        - total_height `Number` - Height of entire spritesheet\n        - image `String` - Relative URL path from CSS to spritesheet\n        - escaped_image `String` - URL encoded `image`\n        - px `Object` - Container for numeric values including `px`\n            - width `String` - `width` suffixed with `px`\n            - height `String` - `height` suffixed with `px`\n    - spritesheet_info `Object` - Container for `spritesheet` metadata and its representation\n        - name `String` - Prefix for spritesheet variables\n    - retina_sprites `Object[]` - Array of retina sprite information\n        - This will only be accessible if we are generating a retina spritesheet\n        - Properties are the same as `sprites` (e.g. `name`, `width`, `source_image`)\n    - retina_spritesheet `Object` - Information about retina spritesheet\n        - This will only be accessible if we are generating a retina spritesheet\n        - Properties are the same as `spritesheet` (e.g. `width`, `px`)\n    - retina_spritesheet_info `Object` - Container for `retina_spritesheet` metadata and its representation\n        - This will only be accessible if we are generating a retina spritesheet\n        - name `String` - Prefix for spritesheet variables\n    - retina_groups `Object[]` - Array of objects that maps to normal and retina sprites\n        - This will only be accessible if we are generating a retina spritesheet\n        - * `Object` - Container for data about sprite mapping\n            - name `String` - Name to refer to mapping by\n            - index `Number` - Index of corresponding normal/retina sprites from `data.sprites`/`data.retina_sprites`\n            - normal `Object` - Normal sprite from `data.sprites` that corresponds to our mapping\n                - This has all the same properties as `data.sprites[*]` (e.g. `name`, `x`, `offset_y`, `px`)\n            - retina `Object` - Retina sprite from `data.retina_sprites` that corresponds to our mapping\n                - This has all the same properties as `data.retina_sprites[*]` (e.g. `name`, `x`, `offset_y`, `px`)\n    - retina_groups_info `Object` - Optional container for metadata about `retina_groups` and its representation\n        - This will only be accessible if we are generating a retina spritesheet\n        - name `String` - Name for `retina_groups`\n    - options `Object` - Options passed in via `cssOpts` in `gulp.spritesmith` config\n\n[`spritesheet-templates`]: https://github.com/twolfson/spritesheet-templates\n\nAn example `sprite` is\n\n```js\n{\n  \"name\": \"sprite2\",\n  \"x\": 10,\n  \"y\": 20,\n  \"width\": 20,\n  \"height\": 30,\n  \"total_width\": 80,\n  \"total_height\": 100,\n  \"image\": \"nested/dir/spritesheet.png\",\n  \"escaped_image\": \"nested/dir/spritesheet.png\",\n  \"source_image\": \"path/to/original/sprite.png\",\n  \"offset_x\": -10,\n  \"offset_y\": -20,\n  \"px\": {\n    \"x\": \"10px\",\n    \"y\": \"20px\",\n    \"width\": \"20px\",\n    \"height\": \"30px\",\n    \"total_width\": \"80px\",\n    \"total_height\": \"100px\",\n    \"offset_x\": \"-10px\",\n    \"offset_y\": \"-20px\"\n  }\n}\n```\n\nIf you are defining a Handlebars template, then you can inherit from an existing template via [`handlebars-layouts`][] (e.g. `{{#extend \"scss\"}}`). An example usage can be found in the [Examples section](#handlebars-inheritance).\n\n[`handlebars-layouts`]: https://github.com/shannonmoeller/handlebars-layouts\n\nExample usages can be found as:\n\n- [Handlebars template](#handlebars-template)\n- [Handlebars inheritance](#handlebars-inheritance)\n- [Template function](#template-function)\n\n#### Variable mapping\nThe `cssVarMap` option allows customization of the CSS variable names\n\n\u003e If you would like to customize CSS selectors in the `css` template, please see https://github.com/twolfson/spritesheet-templates#css\n\nYour `cssVarMap` should be a function with the signature `function (sprite)`. It will receive the same parameters as `sprites` from [Templating](#templating) except for `escaped_image`, `offset_x`,` offset_y`, and `px`.\n\n```js\n// Prefix all sprite names with `sprite-` (e.g. `home` -\u003e `sprite-home`)\ncssVarMap: function (sprite) {\n  sprite.name = 'sprite_' + sprite.name;\n}\n\n// Generates:\n// $sprite_fork_x = 0px;\n// $sprite_fork_y = 0px;\n\n// As oppposed to default:\n// $fork_x = 0px;\n// $fork_y = 0px;\n```\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[`pixelsmith`]: https://github.com/twolfson/pixelsmith\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\nIn this example, we are using the `alt-diagonal` algorithm to guarantee no overlap if images overflow.\n\n**Configuration:**\n\n```js\n{\n  imgName: 'sprite.png',\n  cssName: 'sprite.styl',\n  algorithm: 'alt-diagonal'\n}\n```\n\n**Output:**\n\n![algorithm spritesheet](docs/examples/algorithm/sprite.png)\n\n### Engine\nIn this example, we are using the `phantomjssmith` engine as an alternative to the `pixelsmith` default.\n\n**Requirements:**\n\nInstall `phantomjssmith` to our `node_modules` via `npm install`.\n\n```bash\nnpm install phantomjssmith\n```\n\nAlternatively, we can use `--save` or `--save-dev` to save to our `package.json's dependencies` or `devDependenices`.\n\n```bash\nnpm install phantomjssmith --save  # Updates {\"dependencies\": {\"phantomjssmith\": \"1.2.3\"}}\nnpm install phantomjssmith --save-dev  # Updates {\"devDependencies\": {\"phantomjssmith\": \"1.2.3\"}}\n```\n\n**Configuration:**\n\n```js\n// var phantomjssmith = require('phantomjssmith');\n{\n  imgName: 'sprite.png',\n  cssName: 'sprite.styl',\n  engine: phantomjssmith\n}\n```\n\n**Output:**\n\n![engine spritesheet](docs/examples/engine/sprite.png)\n\n### Padding\nThe `padding` option allows for inserting spacing between images.\n\n**Configuration:**\n\n```js\n{\n  imgName: 'sprite.png',\n  cssName: 'sprite.styl',\n  padding: 20 // Exaggerated for visibility, normal usage is 1 or 2\n}\n```\n\n**Output:**\n\n![padding spritesheet](docs/examples/padding/sprite.png)\n\n### Retina spritesheet\nIn this example, we will use generate a normal and retina spritesheet via the `retinaSrcFilter` and `retinaImgName` parameters.\n\n**Configuration:**\n\n```js\n{\n  // This will filter out `fork@2x.png`, `github@2x.png`, ... for our retina spritesheet\n  //   The normal spritesheet will now receive `fork.png`, `github.png`, ...\n  retinaSrcFilter: ['images/*@2x.png'],\n  imgName: 'sprite.png',\n  retinaImgName: 'sprite@2x.png',\n  cssName: 'sprite.styl'\n}\n```\n\n**Normal spritesheet:**\n\n![Normal spritesheet](docs/examples/retina/sprite.png)\n\n**Retina spritesheet:**\n\n![Retina spritesheet](docs/examples/retina/sprite@2x.png)\n\n### Handlebars template\nIn this example, we will use `cssTemplate` with a `handlebars` template to generate CSS that uses `:before` selectors.\n\n**Template:**\n\n```handlebars\n{{#sprites}}\n.icon-{{name}}:before {\n  display: block;\n  background-image: url({{{escaped_image}}});\n  background-position: {{px.offset_x}} {{px.offset_y}};\n  width: {{px.width}};\n  height: {{px.height}};\n}\n{{/sprites}}\n```\n\n**Configuration:**\n\n```js\n{\n  imgName: 'sprite.png',\n  cssName: 'sprite.css',\n  cssTemplate: 'handlebarsStr.css.handlebars'\n}\n```\n\n**Output:**\n\n```css\n.icon-fork:before {\n  display: block;\n  background-image: url(sprite.png);\n  background-position: 0px 0px;\n  width: 32px;\n  height: 32px;\n}\n.icon-github:before {\n/* ... */\n```\n\n### Handlebars inheritance\nIn this example, we will extend the SCSS template to provide minimal variables. The JSON at the front comes from the original template and is required to provide consistent casing and default options.\n\nDifferent block sections for each template are documented in:\n\nhttps://github.com/twolfson/spritesheet-templates\n\n**Template:**\n\n```handlebars\n{\n  // Default options\n  'functions': true,\n  'variableNameTransforms': ['dasherize']\n}\n\n{{#extend \"scss\"}}\n{{#content \"sprites\"}}\n{{#each sprites}}\n${{strings.name}}: ({{px.x}}, {{px.y}}, {{px.offset_x}}, {{px.offset_y}}, {{px.width}}, {{px.height}}, {{px.total_width}}, {{px.total_height}}, '{{{escaped_image}}}', '{{name}}', );\n{{/each}}\n{{/content}}\n{{#content \"spritesheet\"}}\n${{spritesheet_info.strings.name_sprites}}: ({{#each sprites}}${{strings.name}}, {{/each}});\n${{spritesheet_info.strings.name}}: ({{spritesheet.px.width}}, {{spritesheet.px.height}}, '{{{spritesheet.escaped_image}}}', ${{spritesheet_info.strings.name_sprites}}, );\n{{/content}}\n{{/extend}}\n```\n\n**Configuration:**\n\n```js\n{\n  imgName: 'sprite.png',\n  cssName: 'sprite.scss',\n  cssTemplate: 'handlebarsInheritance.scss.handlebars'\n}\n```\n\n**Output:**\n\n```scss\n$fork: (0px, 0px, 0px, 0px, 32px, 32px, 64px, 64px, 'sprite.png', 'fork', );\n$github: (32px, 0px, -32px, 0px, 32px, 32px, 64px, 64px, 'sprite.png', 'github', );\n$twitter: (0px, 32px, 0px, -32px, 32px, 32px, 64px, 64px, 'sprite.png', 'twitter', );\n$spritesheet-sprites: ($fork, $github, $twitter, );\n$spritesheet: (64px, 64px, 'sprite.png', $spritesheet-sprites, );\n/* ... */\n```\n\n### Template function\nIn this example, we will use `cssTemplate` with a custom function that generates YAML.\n\n**Configuration:**\n\n```js\n// var yaml = require('js-yaml');\n{\n  imgName: 'sprite.png',\n  cssName: 'sprite.yml',\n  cssTemplate: function (data) {\n    // Convert sprites from an array into an object\n    var spriteObj = {};\n    data.sprites.forEach(function (sprite) {\n      // Grab the name and store the sprite under it\n      var name = sprite.name;\n      spriteObj[name] = sprite;\n\n      // Delete the name from the sprite\n      delete sprite.name;\n    });\n\n    // Return stringified spriteObj\n    return yaml.safeDump(spriteObj);\n  }\n}\n```\n\n**Output:**\n\n```yaml\nfork:\n  x: 0\n  'y': 0\n  width: 32\n  height: 32\n  source_image: /home/todd/github/gulp.spritesmith/docs/images/fork.png\n  image: sprite.png\n  total_width: 64\n  total_height: 64\n  escaped_image: sprite.png\n  offset_x: -0.0\n  offset_y: -0.0\n  px:\n    x: 0px\n    'y': 0px\n    offset_x: 0px\n    offset_y: 0px\n    height: 32px\n    width: 32px\n    total_height: 64px\n    total_width: 64px\ngithub:\n# ...\n```\n\n### Cache busting\n`gulp.spritesmith` doesn't directly support cache busting but [`gulp-spritesmash`][] is a plugin that takes `gulp.spritesmith's` output and generates cache busted filenames and CSS URLs. Here's an example usage:\n\n\u003chttps://github.com/MasterOfMalt/gulp-spritesmash\u003e\n\n```js\nvar gulp = require('gulp');\nvar buffer = require('vinyl-buffer');\nvar spritesmash = require('gulp-spritesmash');\nvar spritesmith = require('gulp.spritesmith');\n\ngulp.task('sprite', function () {\n  return gulp.src('images/*.png', {encoding: false})\n      .pipe(spritesmith({\n        imgName: 'sprite.png',\n        cssName: 'sprite.css'\n      }))\n      .pipe(buffer())\n      .pipe(spritesmash());\n      .pipe(gulp.dest('path/to/output/', {encoding: false}));\n});\n```\n\n[`gulp-spritesmash`]: https://github.com/MasterOfMalt/gulp-spritesmash\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\nGitHub and Twitter icons were taken from [Alex Peattie's JustVector Social Icons][justvector].\n\nFork designed by [P.J. Onori][onori] from The Noun Project.\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\n## Unlicense\nAs of Feb 09 2014, Todd Wolfson has released this repository and its contents to the public domain.\n\nIt has been released under the [UNLICENSE][].\n\n[UNLICENSE]: UNLICENSE\n","funding_links":["https://twolfson.com/support-me"],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwolfson%2Fgulp.spritesmith","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwolfson%2Fgulp.spritesmith","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwolfson%2Fgulp.spritesmith/lists"}