getImageDimensions()
@remotion/media-utils 包的一部分辅助函数。从 v4.0.143 起可用.
🌐 Part of the @remotion/media-utils package of helper functions. Available from v4.0.143.
获取图片 src 的尺寸,检索图片的宽度和高度。
🌐 Takes an image src, retrieves the dimensions of an image.
参数
🌐 Arguments
src
一个指定图片 URL 或路径的字符串。
🌐 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
图片宽度,以像素(px)为单位。
🌐 The image width, in pixels (px).
height
number
图片高度,以像素(px)为单位。
🌐 The image height, in pixels (px).
示例
🌐 Example
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.
如果你多次传入相同的参数给 src,从第二次开始它将返回缓存的版本,无论文件是否已更改。
要清除缓存,你必须重新加载页面。
🌐 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