图像大小
安装
# npm
npm install @coderosh/image-size
# yarn
yarn add @coderosh/image-size
使用量
-
图像源作为 url (nodejs 和浏览器)
import imageSize from '@coderosh/image-size' const main = async () => { const url = 'https://ulka.js.org/logo.png' const size = await imageSize(url) console.log(size) // { height: 827, width: 738 } } -
作为阵列缓冲器的图像源( 节点和浏览器)
import imageSize from '@coderosh/image-size' const main = async () => { const url = 'https://ulka.js.org/logo.png' const ab = await fetch(url).then((res) => res.arrayBuffer()) const size = await imageSize(ab) console.log(size) // { height: 827, width: 738 } } -
图像源作为缓冲( 只有节点)
import imageSize from '@coderosh/image-size' const main = async () => { const url = 'https://ulka.js.org/logo.png' const buffer = await fetch(url).then((res) => res.buffer()) const size = await imageSize(buffer) console.log(size) // { height: 827, width: 738 } } -
图像源为 blob( 仅浏览器)
import imageSize from '@coderosh/image-size' const main = async () => { const url = 'https://ulka.js.org/logo.png' const blob = await fetch(url).then((res) => res.blob()) const size = await imageSize(blob) console.log(size) // { height: 827, width: 738 } }
许可证
麻省理工学院