nodeca/probe-image-size
nodeca/probe-image-size has 1,032 GitHub stars and 73 forks. GitHot measured +1 in 7 days. Last checked 2026-11-11 02:19 UTC. Last push 2026-10-27.
Get image size without full download. Supported image types: JPG, GIF, PNG, WebP, BMP, TIFF, SVG, PSD, ICO.
Measured star growth
- in 24h
- Update delayed
- in 7 days
- +1
- in 15 days
- Collecting history
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
Originalprobe-image-size
Get image size without full download. Supported image types: JPG, GIF, PNG, WebP, BMP, TIFF, SVG, PSD, ICO, AVIF, HEIC, HEIF.
Key features:
- small size, no heavy dependencies
- works with remote and local data
- effective with big images (speed/memory), download minimal data from remotes
- extracts orientation value when available
- easy to browserify (splitted to components)
Install
npm install probe-image-size
Example
const probe = require('probe-image-size');
// Get by URL
let result = await probe('http://example.com/image.jpg');
console.log(result); // =>
/*
{
width: xx,
height: yy,
type: 'jpg',
mime: 'image/jpeg',
wUnits: 'px',
hUnits: 'px',
url: 'http://example.com/image.jpg'
}
*/
// By URL with options
let result = await probe('http://example.com/image.jpg', { rejectUnauthorized: false });
console.log(result);
// From the stream
let result = await probe(require('fs').createReadStream('image.jpg'));
console.log(result);
// From a Buffer (sync)
let data = require('fs').readFileSync('image.jpg');
console.log(probe.sync(data));
Security notes
Network requests. The library uses GET requests to extract image metadata. The default HTTP wrapper supports requests to localhost and private networks. Such requests are not a security issue on their own.
If HTTP(S) GET requests to internal services are a concern, block access to local and private networks at the interface or network level. A separate VM lets you configure these restrictions independently.
Image dimensions. For untrusted images, treat the returned width and height
as untrusted too. Check that they are within ranges acceptable for your application.
API
Note:
- You can access/browserify
stream.js/http.js/sync.jsdirectly. - If you don't like
http.jsdependencies, you can create your own wrapper forstream.js.
probe(src [, options|keepOpen]) -> Promise
See Security notes when working with untrusted input.
srccan be of this types:- String - URL to fetch
- Stream - readable stream
options- HTTP only. Seeneedledocumentation, and customized defaults.keepOpen(Boolean) - stream only. Keep stream open after parser finishes (input stream will be closed by default)
result (Promise) contains:
{
width: XX,
height: YY,
length: ZZ, // byte length of the file (if available, HTTP only)
type: ..., // image 'type' (usual file name extention)
mime: ..., // mime type
wUnits: 'px', // width units type ('px' by default, can be different for SVG)
hUnits: 'px', // height units type ('px' by default, can be different for SVG)
url: ..., // HTTP only, last url for the image in chain of redirects
// (if no redirects, same as src)
// optional, image orientation (from Exif), number from 1 to 8;
// you may wish to swap width and height if orientation is >= 5
orientation: X,
// optional, full list of sizes for ICO (always) and AVIF (if multiple images)
variants: [ { width, height }, ... ] | undefined
}
Width and height in the output object represent image size before any transformations (orientation, cropping) are applied. Orientation is returned separately, which you may wish to apply afterwards depending on browser support (browsers only support JPEG orientation for now). See known issues for details.
Returned errors can be extended with 2 fields:
code- equals toECONTENTif the library failed to parse the file;status- equals to a HTTP status code if it receives a non-200 response.
probe.sync(src) -> result|null
Sync version can eat arrays, typed arrays and buffers. On success it returns the same result as async version. On fail it returns null.
[!NOTE]
Formats like JPEG & TIFF can store size anywhere (far from the head). That usually does not happens, but if you need guarantees - always provide full file content to sync methods. We strongly recommend to use async version as memory-friendly.
Similar projects
Support probe-image-size
You can support this project via Tidelift subscription.
Explore related projects
ytdl-org/youtube-dl
Command-line program to download videos from YouTube.com and other video sites
141,527 starsexcalidraw/excalidraw
Virtual whiteboard for sketching hand-drawn like diagrams
135,396 starsgodotengine/godot
Godot Engine – Multi-platform 2D and 3D game engine
119,942 starsmrdoob/three.js
JavaScript 3D Library.
117,983 stars