isomorphic-image-size
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

isomorphic-image-size 📸📏

badge of current npm version badge of minified + gzip 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',
  }
*/

Similar projects

Package Sidebar

Install

npm i isomorphic-image-size

Weekly Downloads

9

Version

1.0.6

License

MIT

Unpacked Size

36 kB

Total Files

19

Last publish

Collaborators

  • jamsinclair