# get-image-pixels

> gets a RGBA array of the given Image/Video source

Latest version **1.0.1** (published 2016-03-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install get-image-pixels
pnpm add get-image-pixels
yarn add get-image-pixels
bun add get-image-pixels
```

## 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.0.1 |
| Published | 2016-03-19 |
| First published | 2014-08-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 21 |
| Author | Matt DesLauriers |
| Maintainers | mattdesl |
| Keywords | gl, webgl, glsl, stackgl, modules-gl, gl-modules, image, pixel, imagedata, canvas, pixels, uint8array, rgba, rgb |

## Links

- npm: https://www.npmjs.com/package/get-image-pixels
- Repository: https://github.com/mattdesl/get-image-pixels
- Issues: https://github.com/mattdesl/get-image-pixels/issues
- npm.io page: https://npm.io/package/get-image-pixels

## 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.0.1 (latest) — 2016-03-19
- 1.0.0 — 2014-08-26

## README

[![browser support](https://ci.testling.com/mattdesl/get-image-pixels.png)](https://ci.testling.com/mattdesl/get-image-pixels)

# get-image-pixels

[![experimental](http://badges.github.io/stability-badges/dist/experimental.svg)](http://github.com/badges/stability-badges)

Uses an intermediary canvas node to grab the RGBA pixels of the given source, with an optional clipping region. Works on HTML Canvas, Image, and Video elements.

```js
var getPixels = require('get-image-pixels')

var data = getPixels(myImage) // returns a Uint8Array
console.log( data.length === (myImage.width * myImage.height * 4) ) //true
```

Or, with clipping:

```js
var halfWidth = myImage.width/2
var data = getPixels(myImage, { x: halfWidth, width: halfWidth })
console.log( data.length === (halfWidth * myImage.height * 4) ) //true
```

## Usage

[![NPM](https://nodei.co/npm/get-image-pixels.png)](https://nodei.co/npm/get-image-pixels/)

### `getPixels(image[, opts])`

Gets the RGBA pixels from HTML Image/Video/Canvas element as a Uint8Array with some optional parameters.

- `x` the x position to start clipping, default 0
- `y` the y position to start clipping, default 0
- `width` the width of the source to copy; this will change the returned array's shape. defaults to image width
- `height` the height of the source to copy; this will change the returned array's shape. defaults to image height

### `getPixels.dispose()`

Release the shared canvas for GC. This is mainly useful if you need to minimize disruptive GC hitches, e.g. in a game loop. 

## License

MIT, see [LICENSE.md](http://github.com/mattdesl/get-image-pixels/blob/master/LICENSE.md) for details.

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