isomorphic-image-size
v1.0.6
Published
Get image size without rendering in browser or node. Isomorphic, Zero Dependencies, Lightweight.
Downloads
49
Maintainers
Readme
isomorphic-image-size 📸📏
Get image size without rendering. Supported image types: JPG, GIF, PNG, WebP, BMP, TIFF, SVG, PSD, ICO, AVIF, HEIC, HEIF.
Key features:
- Zero dependencies
- Tiny size, 4KB gzipped
- Isomorphic, works both in browser and node without changing anything
- Extracts orientation value when available
This code is an ES Module fork of probe-image-size and inspired by enhancements from image-sizer.
Usage
npm install isomorphic-image-size
import sizer from 'isomorphic-image-size'
const res = await fetch('http://example.com/image.jpg')
const data = await res.arrayBuffer()
const sizeInfo = sizer(data)
console.log(sizeInfo); // =>
/*
{
width: xx,
height: yy,
type: 'jpg',
mime: 'image/jpeg',
wUnits: 'px',
hUnits: 'px',
}
*/
// If you know the type of image you can run sizer with an extension
let sizeInfo = sizer(data, 'jpg')
console.log(sizeInfo); // =>
/*
{
width: xx,
height: yy,
type: 'jpg',
mime: 'image/jpeg',
wUnits: 'px',
hUnits: 'px',
}
*/