# fast-png

> PNG image decoder and encoder written entirely in JavaScript

Latest version **8.0.0** (published 2025-12-18) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 50/100 (C)** — status: stable.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 8.0.0 |
| Published | 2025-12-18 |
| First published | 2015-09-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 2 |
| Unpacked size | 159.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 459 |
| Author | Michaël Zasso |
| Maintainers | lpatiny, stropitek, targos, cheminfo-bot |
| Keywords | png, image, image-js, encoder, decoder |

## Links

- npm: https://www.npmjs.com/package/fast-png
- Repository: https://github.com/image-js/fast-png
- Homepage: https://image-js.github.io/fast-png/
- Issues: https://github.com/image-js/fast-png/issues
- npm.io page: https://npm.io/package/fast-png

## Dependencies (2)

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

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 8.0.0 (latest) — 2025-12-18
- 7.0.1 — 2025-08-13
- 7.0.0 — 2025-06-15
- 6.4.0 — 2025-06-11
- 6.3.0 — 2025-02-25
- 6.2.0 — 2023-07-18
- 6.1.0 — 2021-10-18
- 6.0.1 — 2021-10-12
- 6.0.0 — 2021-10-08
- 5.0.4 — 2021-03-26
- 5.0.3 — 2020-12-14
- 5.0.2 — 2020-02-28
- 5.0.1 — 2019-11-12
- 5.0.0 — 2019-11-12
- 4.0.1 — 2019-04-01
- … 14 more at https://npm.io/package/fast-png/versions

## README

<h3 align="center">
  <a href="https://www.zakodium.com">
    <img src="https://www.zakodium.com/brand/zakodium-logo-white.svg" width="50" alt="Zakodium logo" />
  </a>
  <p>
    Maintained by <a href="https://www.zakodium.com">Zakodium</a>
  </p>
</h3>

# fast-png

[![NPM version](https://img.shields.io/npm/v/fast-png.svg)](https://www.npmjs.com/package/fast-png)
[![npm download](https://img.shields.io/npm/dm/fast-png.svg)](https://www.npmjs.com/package/fast-png)
[![test coverage](https://img.shields.io/codecov/c/github/image-js/fast-png.svg)](https://codecov.io/gh/image-js/fast-png)
[![license](https://img.shields.io/npm/l/fast-png.svg)](https://github.com/image-js/fast-png/blob/main/LICENSE)

PNG image decoder and encoder written entirely in JavaScript.

## Installation

```console
npm install fast-png
```

## API

### [Complete API documentation](https://image-js.github.io/fast-png/)

### `decode(png[, options])`

#### Arguments

- `png` - A TypedArray or Buffer that contains the PNG data.
- `options` - An object of options

#### Options

- `checkCrc` - If set to `true`, the CRC will be checked for each chunk and an error will be thrown in case it's wrong (default: false).

### `encode(image)`

#### Arguments

- `png` - An object representing the image. You can pass an ImageData from the Canvas API or an object with the following properties:
  - `width` - The width of the image
  - `height` - The height of the image
  - `data` - An array or TypedArray with the image data
  - `depth` - A number indicating the color depth (only 8 and 16 are supported now). Default: `8`.
  - `channels` - Number of channels, including alpha (1, 2, 3 and 4 are supported). Default: `4`.
  - `text` - An object with key-value pairs representing `tEXt` chunks. The keys must have less than 80 characters.
    The keys and values must have only characters in the latin1 charset (maximum code point of 255).
    Default: `undefined`.

### `hasPngSignature(array)`

Returns whether the array starts with the PNG signature (magic bytes).

## PNG standard

Spec can be found at: https://www.w3.org/TR/PNG/

## License

[MIT](./LICENSE)

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