# canvassmith

> node-canvas engine for spritesmith

Latest version **1.7.0** (published 2022-05-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install canvassmith
pnpm add canvassmith
yarn add canvassmith
bun add canvassmith
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.7.0 |
| Published | 2022-05-08 |
| First published | 2013-04-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 6.0.0 |
| Dependencies | 4 |
| Unpacked size | 13.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Todd Wolfson |
| Maintainers | twolfson |
| Keywords | spritesmith, image, spritesmith-engine |

## Links

- npm: https://www.npmjs.com/package/canvassmith
- Repository: https://github.com/twolfson/canvassmith
- Issues: https://github.com/twolfson/canvassmith/issues
- npm.io page: https://npm.io/package/canvassmith

## Dependencies (4)

- [async](https://npm.io/package/async.md) ~2.6.4
- [canvas](https://npm.io/package/canvas.md) ~2.7.0
- [vinyl-file](https://npm.io/package/vinyl-file.md) ~1.3.0
- [concat-stream](https://npm.io/package/concat-stream.md) ~1.6.2

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 1.7.0 (latest) — 2022-05-08
- 1.6.0 — 2021-05-12
- 1.5.0 — 2019-12-05
- 1.4.1 — 2018-06-02
- 1.4.0 — 2018-06-02
- 1.3.0 — 2018-01-06
- 1.2.1 — 2017-11-14
- 1.2.0 — 2017-08-23
- 1.1.0 — 2016-05-18
- 1.0.0 — 2015-11-18
- 0.4.4 — 2015-11-12
- 0.4.3 — 2015-11-12
- 0.4.2 — 2015-11-04
- 0.4.1 — 2015-11-04
- 0.4.0 — 2015-10-27
- … 14 more at https://npm.io/package/canvassmith/versions

## README

# canvassmith [![Build status](https://travis-ci.org/twolfson/canvassmith.png?branch=master)](https://travis-ci.org/twolfson/canvassmith)

[node-canvas][canvas] engine for [spritesmith][].

[canvas]: https://github.com/Automattic/node-canvas
[spritesmith]: https://github.com/Ensighten/spritesmith

## Requirements
By default, binaries for macOS, Linux and Windows will be downloaded.
But if you don't have a supported OS or processor architecture the module will be compiled on your system.
This requires several dependencies from [node-canvas][canvas], you must install [Cairo][] and [Pango][].

Instructions on how to do this are provided in the [node-canvas wiki][canvas-wiki].

Additionally, you will need to install [node-gyp][].

[Cairo]: http://cairographics.org/
[Pango]: https://pango.gnome.org/
[canvas-wiki]: https://github.com/Automattic/node-canvas/wiki/_pages
[node-gyp]: https://github.com/nodejs/node-gyp

```bash
npm install -g node-gyp
```

## Getting Started
Install the module with: `npm install canvassmith`

```js
// Load in our dependencies
var Canvassmith = require('canvassmith');

// Create a new engine
var canvassmith = new Canvassmith();

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

## 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][twolfson-projects] via [donations][twolfson-support-me].

<http://twolfson.com/support-me>

[twolfson-projects]: http://twolfson.com/projects
[twolfson-support-me]: http://twolfson.com/support-me

## License
Copyright (c) 2013 Todd Wolfson

Licensed under the MIT license.

---
_Source: https://npm.io/package/canvassmith · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
