getImageDimensions()
@remotion/media-utils
包中的辅助函数之一。从 v4.0.143 版本开始提供。
接受一个图片 src
,检索图片的尺寸。
参数
src
一个指定图片的 URL 或路径的字符串。
返回值
Promise<ImageDimensions>
一个包含有关图片尺寸信息的对象:
width
number
图片宽度,以像素(px)为单位。
height
number
图片高度,以像素(px)为单位。
示例
ts
import {getImageDimensions } from "@remotion/media-utils";const {width ,height } = awaitgetImageDimensions ("https://example.com/remote-image.png",);console .log (width ,height );
ts
import {getImageDimensions } from "@remotion/media-utils";const {width ,height } = awaitgetImageDimensions ("https://example.com/remote-image.png",);console .log (width ,height );
缓存行为
此函数会对其返回的结果进行记忆。
如果多次将相同的参数传递给 src
,它将从第二次开始返回缓存的版本,无论文件是否已更改。
要清除缓存,您必须重新加载页面。