
Security News
AI Agent Lands PRs in Major OSS Projects, Targets Maintainers via Cold Outreach
An AI agent is merging PRs into major OSS projects and cold-emailing maintainers to drum up more work.
image-dimensions
Advanced tools
Get the dimensions of an image
Works in any modern JavaScript environment (browsers, Node.js, Bun, Deno, etc).
Supporting all kinds of image formats is a non-goal. However, pull requests for adding JPEG XL are welcome.
npm install image-dimensions
import {imageDimensionsFromStream} from 'image-dimensions';
// In this example, it will only read a few bytes of the image instead of fetching the whole thing.
const url = 'https://sindresorhus.com/unicorn';
const {body} = await fetch(url);
console.log(await imageDimensionsFromStream(body));
//=> {width: 1920, height: 1080}
imageDimensionsFromStream(stream: ReadableStream<Uint8Array>): Promise<{width: number; height: number} | undefined>Get the dimensions of an image by reading the least amount of data.
Prefer this method.
Returns the image dimensions, or undefined if the image format is not supported or the image data is invalid.
Note: Returns raw pixel dimensions; orientation (EXIF or HEIF/AVIF irot) is not applied.
// Node.js example
import {createReadStream} from 'node:fs';
import {imageDimensionsFromStream} from 'image-dimensions';
const stream = ReadableStream.from(createReadStream('unicorn.png'));
console.log(await imageDimensionsFromStream(stream));
//=> {width: 1920, height: 1080}
imageDimensionsFromData(data: Uint8Array): {width: number; height: number} | undefinedGet the dimensions of an image from data.
This method can be useful if you already have the image loaded in memory.
Returns the image dimensions, or undefined if the image format is not supported or the image data is invalid.
Note: Returns raw pixel dimensions; orientation (EXIF or HEIF/AVIF irot) is not applied.
import {imageDimensionsFromData} from 'image-dimensions';
const data = getImage();
console.log(imageDimensionsFromData(data));
//=> {width: 1920, height: 1080}
npx image-dimensions unicorn.png
630x400
image-size?Advantages of this package
Advantages of image-size
FAQs
Get the dimensions of an image
The npm package image-dimensions receives a total of 119,284 weekly downloads. As such, image-dimensions popularity was classified as popular.
We found that image-dimensions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
An AI agent is merging PRs into major OSS projects and cold-emailing maintainers to drum up more work.

Research
/Security News
Chrome extension CL Suite by @CLMasters neutralizes 2FA for Facebook and Meta Business accounts while exfiltrating Business Manager contact and analytics data.

Security News
After Matplotlib rejected an AI-written PR, the agent fired back with a blog post, igniting debate over AI contributions and maintainer burden.