@unpic/pixels
TypeScript icon, indicating that this package has built-in type declarations

1.2.2 • Public • Published

🌈 @unpic/pixels

Load and decode the pixels for a PNG or JPEG image in Node

This module will take the raw data or URL of a PNG or JPEG image and return the decoded pixels and dimensions of the image.

Usage

import { getPixels } from "@unpic/pixels";

// From a URL
const { width, height, data } = await getPixels(
  "http://placekitten.com/100/100",
);

// From a file

const file = await fs.readFile("kitten.png");

const { width, height, data } = await getPixels(file);

There is also a getFormat function that will return the format of the image data. This is detected by the first magic bytes at the start of the data.

import { getFormat } from "@unpic/pixels";

const file = await fs.readFile("kitten.png");
const format = getFormat(file);
// format === "png"

License

© 2023 Matt Kane. This project is MIT licensed.

Readme

Keywords

none

Package Sidebar

Install

npm i @unpic/pixels

Weekly Downloads

780

Version

1.2.2

License

MIT

Unpacked Size

53.3 kB

Total Files

28

Last publish

Collaborators

  • ascorbic