Skip to content

unjs/image-meta

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Folders and files

NameName
Last commit message
Last commit date
Jan 17, 2025
Jul 3, 2024
Jul 3, 2024
Oct 17, 2023
Jul 3, 2024
Oct 17, 2023
Jul 3, 2024
Oct 17, 2023
Jan 21, 2025
Jul 3, 2024
Feb 13, 2025
Feb 13, 2025
Oct 17, 2023
Jul 3, 2024

Repository files navigation

image-meta

npm version npm downloads bundle Codecov

Detect image type and size using pure javascript.

Usage

Install package:

# npm
npm install image-meta

# yarn
yarn add image-meta

# pnpm
pnpm install image-meta

# bun
bun install image-meta
import { imageMeta } from "image-meta";

const data = await fetch(url).then((res) => res.buffer());

// Meta contains { type, width?, height?, orientation? }
const meta = imageMeta(data);

Note: imageMeta throws an error if either data is not a Buffer/Uint8Array, or data is invalid or type cannot be determined. You should wrap it into a try/catch statement to handle errors.

Development

  • Clone this repository
  • Install the latest LTS version of Node.js
  • Enable Corepack using corepack enable
  • Install dependencies using pnpm install
  • Run interactive tests using pnpm dev

License

Made with ๐Ÿ’›

๐Ÿ”€ Based on image-size by Aditya Yadav and contributors.

Published under MIT License.