# pxls

> Get 4-channel pixels array from an ndarray or nested array

Latest version **2.3.2** (published 2019-01-26) · MIT license · 0 weekly downloads

## Install

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

## 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.3.2 |
| Published | 2019-01-26 |
| First published | 2018-10-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 14.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Dmitry Yv. |
| Maintainers | dy |
| Keywords | uint8, color, array-buffer, pixels-array, rgba-array, color-array, ndarray, normalize, pixels |

## Links

- npm: https://www.npmjs.com/package/pxls
- Repository: https://github.com/dy/pxls
- Homepage: https://github.com/dy/pxls#readme
- Issues: https://github.com/dy/pxls/issues
- npm.io page: https://npm.io/package/pxls

## Dependencies (6)

- [to-uint8](https://npm.io/package/to-uint8.md) ^1.4.1
- [is-buffer](https://npm.io/package/is-buffer.md) ^2.0.3
- [is-browser](https://npm.io/package/is-browser.md) ^2.1.0
- [arr-flatten](https://npm.io/package/arr-flatten.md) ^1.1.0
- [flip-pixels](https://npm.io/package/flip-pixels.md) ^1.0.2
- [compute-dims](https://npm.io/package/compute-dims.md) ^1.1.0

## Alternatives

- [postcss-color-hex-alpha](https://npm.io/package/postcss-color-hex-alpha.md) — 6.4M weekly downloads
- [randomcolor](https://npm.io/package/randomcolor.md) — 348.0K weekly downloads
- [bows](https://npm.io/package/bows.md) — 1.3K weekly downloads
- [ep_prefer_color_scheme](https://npm.io/package/ep_prefer_color_scheme.md) — 260 weekly downloads
- [coc-yank](https://npm.io/package/coc-yank.md) — 61 weekly downloads

## Recent versions

- 2.3.2 (latest) — 2019-01-26
- 2.3.1 — 2018-12-06
- 2.3.0 — 2018-11-25
- 2.2.4 — 2018-11-15
- 2.2.3 — 2018-11-15
- 2.2.2 — 2018-11-15
- 2.2.1 — 2018-11-14
- 2.2.0 — 2018-11-14
- 2.1.0 — 2018-11-13
- 2.0.1 — 2018-11-13
- 2.0.0 — 2018-11-13
- 1.0.2 — 2018-10-26
- 1.0.1 — 2018-10-26
- 1.0.0 — 2018-10-25

## README

# pxls [![unstable](https://img.shields.io/badge/stability-unstable-green.svg)](http://github.com/badges/stability-badges) [![Build Status](https://travis-ci.org/dy/pxls.svg?branch=master)](https://travis-ci.org/dy/pxls)

Take in custom pixels container, return normalized 4-channel Uint8Array with pixels. Detects float/int input pixels, handles Infinities, unfolds structures.

[![npm install pxls](https://nodei.co/npm/pxls.png?mini=true)](https://npmjs.org/package/pxls/)

```js
var pxls = require('pxls')
var ndarray = require('ndarray')

pxls([[0,0,0], [1,1,1]]) // <uint8 0,0,0,255, 255,255,255,255>
pxls([0, 1], 1) // <uint8 0,0,0,255, 255,255,255,255>
pxls([0,0,0, 1,1,1], [2,1]) // <uint8 0,0,0,255, 255,255,255,255>
pxls(new Ndarray([0,1], [2,1]) // <uint8 0,0,0,255, 255,255,255,255>
pxls(new Ndarray([0,0,0,1,1,1], [2,1,3]) // <uint8 0,0,0,255, 255,255,255,255>
```

## `let pixels = pxls(arr, shape|step?)`

Takes input actual pixels container `arr` and returns 4 channels flat _Uint8Array_ `pixels` with layout `[r,g,b,a, r,g,b,a, r,g,b,a, ...]`.

`arr` can be an Array of Arrays, TypedArray, Ndarray, ImageData or DOM container Image, Video, ImageBitmap, Canvas2D, Context2D, WebGLContext.

1-channel input is mapped as grayscale `[v,v,v,255, v,v,v,255]`. 3-channel input fills last channel with `255` `[r,g,b,255, r,g,b,255]`.

`shape` can describe the shape of input array, eg. `[100,100,3]` or `[10,10]`.

`step` optionally can define input number of channels in flat array, that is detected automatically for nested/ndarrays.


## See also

* [to-uint8](https://ghub.io/to-uint8) − convert input argument to uint8 array.
* [ndarray-to-bitmap-rgba](https://github.com/Jam3/ndarray-bitmap-to-rgba) − convert ndarray to rgba bitmap ndarray.

## License

(c) 2018 Dmitry Yv. MIT License

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