Skip to main content

getImageDimensions()

Part of the @remotion/media-utils package of helper functions. Available from v4.0.143.

Takes an image src, retrieves the dimensions of an image.

Arguments

src

A string that specifies the URL or path of the image.

Return value

Promise<ImageDimensions>

An object with information about the image dimensions:

width

number

The image width, in pixels (px).

height

number

The image height, in pixels (px).

Example

ts
import { getImageDimensions } from "@remotion/media-utils";
 
const { width, height } = await getImageDimensions(
"https://example.com/remote-image.png",
);
console.log(width, height);
ts
import { getImageDimensions } from "@remotion/media-utils";
 
const { width, height } = await getImageDimensions(
"https://example.com/remote-image.png",
);
console.log(width, height);

Caching behavior

This function is memoizing the results it returns.

If you pass in the same argument to src multiple times, it will return a cached version from the second time on, regardless of if the file has changed.
To clear the cache, you have to reload the page.

See also