# png-js

> A PNG decoder in JavaScript

Latest version **2.0.0** (published 2026-04-14) · 0 weekly downloads

## Install

```sh
npm install png-js
pnpm add png-js
yarn add png-js
bun add png-js
```

## Health

**Score 55/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2026-04-14 |
| First published | 2012-04-07 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 64.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 501 |
| Author | Devon Govett |
| Maintainers | devongovett, diegomura |

## Links

- npm: https://www.npmjs.com/package/png-js
- Repository: https://github.com/devongovett/png.js
- Homepage: https://github.com/devongovett/png.js#readme
- Issues: http://github.com/devongovett/png.js/issues
- npm.io page: https://npm.io/package/png-js

## Dependencies (1)

- [fflate](https://npm.io/package/fflate.md) ^0.8.2

## Recent versions

- 2.0.0 (latest) — 2026-04-14
- 1.1.0 — 2026-04-14
- 1.0.0 — 2019-11-17
- 0.1.1 — 2012-11-21
- 0.1.0 — 2012-04-07

## README

png.js
======
A PNG decoder in JS for the canvas element or Node.js.

## Browser Usage
Simply include png.js and zlib.js on your HTML page, create a canvas element, and call PNG.load to load an image.

    <canvas></canvas>
    <script src="zlib.js"></script>
    <script src="png.js"></script>
    <script>
        var canvas = document.getElementsByTagName('canvas')[0];
        PNG.load('some.png', canvas);
    </script>
    
The source code for the browser version resides in `png.js` and also supports loading and displaying animated PNGs.
    
## Node.js Usage
Install the module using npm

    sudo npm install png-js
    
Require the module and decode a PNG

    var PNG = require('png-js');
    PNG.decode('some.png', function(pixels) {
        // pixels is a 1d array (in rgba order) of decoded pixel data
    });
    
You can also call `PNG.load` if you want to load the PNG (but not decode the pixels) synchronously.  If you already
have the PNG data in a buffer, simply use `new PNG(buffer)`.  In both of these cases, you need to call `png.decode`
yourself which passes your callback the decoded pixels as a buffer.  If you already have a buffer you want the pixels
copied to, call `copyToImageData` with your buffer and the decoded pixels as returned from `decodePixels`.

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