Get the width and height of a video or image.
Install with npm:
$ npm install --save @jonschlinkert/media-sizeGet the width and height of image and video files.
Images are read with image-size. Videos are read with video-size, which shells out to ffprobe.
npm install media-size
pnpm add media-size
yarn add media-sizeImage sizing works without extra system dependencies.
Video sizing uses video-size, which shells out to ffprobe, so FFmpeg needs to be installed and ffprobe needs to be available on your PATH.
import { mediaSize } from '@jonschlinkert/media-size';
const dimensions = await mediaSize('photo.jpg');
console.log(dimensions);
// { width: 4032, height: 3024, orientation: undefined }
const dimensions = await mediaSize('video.mp4');
console.log(dimensions);
// { width: 1280, height: 720, orientation: 'landscape' }Returns a promise for the dimensions of a supported image or video file.
const dimensions = await mediaSize('photo.webp');Returns null when filepath is not a supported image or video file.
const dimensions = await mediaSize('notes.txt');
console.log(dimensions);
// nullmediaSize returns an object with width,
height, and orientation for supported files:
interface MediaDimensions {
width: number;
height: number;
orientation: unknown;
}Image orientation is passed through from image-size when available. Video orientation is described below.
interface VideoDimensions {
width: number;
height: number;
orientation: 'landscape' | 'portrait' | null;
}Image orientation is passed through from video-size when available. Video orientation is described below.
widthandheightare the encoded dimensions reported byffprobe.orientationis based on the display dimensions. Rotation metadata is respected, so a rotated video can be reported asportraiteven when the encoded width is greater than the encoded height. Square videos returnnull.
Supports the following image extensions:
avifavifsbmpcurddsdibgifheicheicsheifheifsicbicnsicoj2cj2kjfijfifjifjp2jpcjpejpegjpfjpgjpmjxlktxktx2mj2pampbmpfmpgmpngpnmppmpsdsvgsvgztgatiftiffvdavstwebp
Supports the following video types / file extensions:
3g23gpaviflvm2tm2tsm4vmkvmovmp4mpegmpgmtstswebm
- video-size: Get the width and height of a video. | homepage
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)
To generate the readme and API documentation with verb:
$ npm install -g verb verb-generate-readme && verbInstall dev dependencies:
$ npm install -d && npm testJon Schlinkert
Copyright © 2026, Jon Schlinkert. MIT
This file was generated by verb-generate-readme, v0.1.31, on May 16, 2026.