https://github.com/ascorbic/get-pixels
🌈 🦕 Get the decoded pixel data from a JPG or PNG image
https://github.com/ascorbic/get-pixels
Last synced: 9 months ago
JSON representation
🌈 🦕 Get the decoded pixel data from a JPG or PNG image
- Host: GitHub
- URL: https://github.com/ascorbic/get-pixels
- Owner: ascorbic
- Created: 2023-01-30T08:09:47.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-02-18T21:39:18.000Z (almost 2 years ago)
- Last Synced: 2024-10-19T22:35:34.741Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 30.3 KB
- Stars: 12
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README-npm.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# 🌈 `@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
```ts
import { getPixels } from "@unpic/pixels";
// From a URL
const { width, height, data } = await getPixels(
"https://placecats.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.
```ts
import { getFormat } from "@unpic/pixels";
const file = await fs.readFile("kitten.png");
const format = getFormat(file);
// format === "png"
```
## License
© 2023-2024 [Matt Kane](https://github.com/ascorbic). This project is MIT
licensed.