Skip to main content

@img/png@0.1.2
Built and signed on GitHub Actions

A image encoder/decoder for the PNG format

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
2 weeks ago (0.1.2)
function decodePNG
decodePNG(input: Uint8Array | Uint8ClampedArray): Promise<{ header: PNGOptions; body: Uint8Array; }>

decodePNG is a function that decodes a PNG image into raw image data. The raw image data is a sequence of [ r, g, b, a ] numbers.

Examples

Example 1

import { decodePNG, encodePNG } from "@img/png";

const encodedData = await encodePNG(
  await new Response(ReadableStream.from(async function* () {
    for (let r = 0; r < 256; ++r) {
      for (let c = 0; c < 256; ++c) {
        yield new Uint8Array([255 - r, c, r, 255]);
      }
    }
  }())).bytes(),
  { width: 256, height: 256, compression: 0, filter: 0, interlace: 0 },
);

console.log((await decodePNG(encodedData)).header);

Parameters

The PNG image.

Return Type

Promise<{ header: PNGOptions; body: Uint8Array; }>

The metadata and raw image data.

Add Package

deno add jsr:@img/png

Import symbol

import { decodePNG } from "@img/png/decode";

---- OR ----

Import directly with a jsr specifier

import { decodePNG } from "jsr:@img/png/decode";

Add Package

npx jsr add @img/png

Import symbol

import { decodePNG } from "@img/png/decode";

Add Package

yarn dlx jsr add @img/png

Import symbol

import { decodePNG } from "@img/png/decode";

Add Package

pnpm dlx jsr add @img/png

Import symbol

import { decodePNG } from "@img/png/decode";

Add Package

bunx jsr add @img/png

Import symbol

import { decodePNG } from "@img/png/decode";