# pixelsmith

> Node based engine for spritesmith

Latest version **2.6.0** (published 2022-04-14) · 0 weekly downloads

## Install

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

## 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 | 2.6.0 |
| Published | 2022-04-14 |
| First published | 2014-11-25 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 12.0.0 |
| Dependencies | 8 |
| Unpacked size | 31.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 24 |
| Author | Todd Wolfson |
| Maintainers | twolfson |
| Keywords | spritesmith, image, spritesmith-engine |

## Links

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

## Dependencies (8)

- [async](https://npm.io/package/async.md) ^3.2.3
- [ndarray](https://npm.io/package/ndarray.md) ~1.0.15
- [get-pixels](https://npm.io/package/get-pixels.md) ~3.3.0
- [mime-types](https://npm.io/package/mime-types.md) ~2.1.7
- [obj-extend](https://npm.io/package/obj-extend.md) ~0.1.0
- [vinyl-file](https://npm.io/package/vinyl-file.md) ~1.3.0
- [save-pixels](https://npm.io/package/save-pixels.md) ~2.3.0
- [concat-stream](https://npm.io/package/concat-stream.md) ~1.5.1

## 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

- 2.6.0 (latest) — 2022-04-14
- 2.5.0 — 2021-09-23
- 2.4.1 — 2019-09-13
- 2.4.0 — 2019-09-13
- 2.3.0 — 2019-09-13
- 2.2.2 — 2019-09-13
- 2.2.1 — 2018-01-06
- 2.2.0 — 2018-01-06
- 2.1.3 — 2017-11-14
- 2.1.2 — 2017-09-24
- 2.1.1 — 2016-05-14
- 2.1.0 — 2016-01-29
- 2.0.1 — 2015-12-16
- 2.0.0 — 2015-11-18
- 1.3.4 — 2015-11-12
- … 11 more at https://npm.io/package/pixelsmith/versions

## README

# pixelsmith [![Build Status](https://app.travis-ci.com/twolfson/pixelsmith.svg?branch=master)](https://app.travis-ci.com/twolfson/pixelsmith)

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

[spritesmith]: https://github.com/Ensighten/spritesmith
[get-pixels]: https://github.com/mikolalysenko/get-pixels
[save-pixels]: https://github.com/mikolalysenko/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`

```js
// 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][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

## 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][].

[UNLICENSE]: UNLICENSE

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