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 encodePNG
encodePNG(): Promise<Uint8Array>

encodePNG is a function that encodes raw image data into the PNG image format. The raw image data is expected to be in a sequence of [ r, g, b, a ] numbers.

Examples

Example 1

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

await Deno.mkdir(".output/", { recursive: true });

const rawData = await new Response(ReadableStream.from(async function* () {
  for (let r = 0; r < 256; ++r) {
    for (let c = 0; c < 256; ++c) {
      yield Uint8Array.from([255 - r, c, r, 255]);
    }
  }
}())).bytes();

await Deno.writeFile(".output/encode.png", await encodePNG(rawData, {
  width: 256,
  height: 256,
  compression: 0,
  filter: 0,
  interlace: 0,
}));

Parameters

The raw image data.

options: PNGOptions

The metadata for the raw image data.

Return Type

An PNG image.

Add Package

deno add jsr:@img/png

Import symbol

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

---- OR ----

Import directly with a jsr specifier

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

Add Package

npx jsr add @img/png

Import symbol

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

Add Package

yarn dlx jsr add @img/png

Import symbol

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

Add Package

pnpm dlx jsr add @img/png

Import symbol

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

Add Package

bunx jsr add @img/png

Import symbol

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