# save-pixels

> Saves an ndarray as an image to a file

Latest version **2.3.6** (published 2021-07-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install save-pixels
pnpm add save-pixels
yarn add save-pixels
bun add save-pixels
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.6 |
| Published | 2021-07-31 |
| First published | 2013-05-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/save-pixels) |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 7.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 92 |
| Author | Mikola Lysenko |
| Maintainers | mikolalysenko, jaspervdg, hughsk, substack, planeshifter, rreusser |
| Keywords | save, pixel, image, png, ndarray |

## Links

- npm: https://www.npmjs.com/package/save-pixels
- Repository: https://github.com/mikolalysenko/save-pixels
- Homepage: https://github.com/mikolalysenko/save-pixels#readme
- Issues: https://github.com/mikolalysenko/save-pixels/issues
- npm.io page: https://npm.io/package/save-pixels

## Dependencies (7)

- [jpeg-js](https://npm.io/package/jpeg-js.md) ^0.4.3
- [ndarray](https://npm.io/package/ndarray.md) ^1.0.18
- [through](https://npm.io/package/through.md) ^2.3.4
- [gif-encoder](https://npm.io/package/gif-encoder.md) ~0.4.1
- [ndarray-ops](https://npm.io/package/ndarray-ops.md) ^1.2.2
- [pngjs-nozlib](https://npm.io/package/pngjs-nozlib.md) ^1.0.0
- [contentstream](https://npm.io/package/contentstream.md) ^1.0.0

## 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.3.6 (latest) — 2021-07-31
- 2.3.5 — 2021-07-15
- 2.3.4 — 2016-08-15
- 2.3.3 — 2016-05-04
- 2.3.2 — 2016-05-03
- 2.3.1 — 2016-05-03
- 2.3.0 — 2015-11-18
- 2.2.1 — 2015-10-05
- 2.2.0 — 2014-11-12
- 2.1.0 — 2014-10-18
- 2.0.0 — 2014-10-18
- 1.0.0 — 2014-05-22
- 0.3.0 — 2013-07-30
- 0.2.1 — 2013-07-30
- 0.2.0 — 2013-06-26
- … 4 more at https://npm.io/package/save-pixels/versions

## README

save-pixels
===========
Saves an ndarray to an image.

Example
=======
```javascript
var zeros = require("zeros")
var savePixels = require("save-pixels")

//Create an image
var x = zeros([32, 32])
x.set(16, 16, 255)

//Save to a file
savePixels(x, "png").pipe(process.stdout)
```

This writes the following image to stdout:

<img src=https://raw.github.com/mikolalysenko/save-pixels/master/example/example.png>

Install
=======

    npm install save-pixels

### `require("save-pixels")(array, type[, options])`
Saves an ndarray as an image with the given format

* `array` is an `ndarray` of pixels.  Assumes that shape is `[width, height, channels]`
* `type` is the type of the image to save.  Currently supported formats:

  + `"jpeg"`, `"jpg"` - Joint Photographic Experts Group format
  + `"gif"` - Graphics Interchange Format
  + `"png"` - Portable Network Graphics format
  + `"canvas"` - A canvas element

* `options` is an object that alters saving behavior

  + `quality` is the `Number` to use for saved image quality

    + This can only be used with a `"jpeg"` image
    + It range between 1 (low quality) and 100 (high quality) inclusively

**Returns** A stream that you can pipe to serialize the result, or a canvas element if the `type` is `"canvas"`.

# Credits
(c) 2013 Mikola Lysenko. MIT License

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