Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

coderosh/image-size

Repository files navigation

image-size

Get height and width of image using Image api in browser and buffer-image-size package in nodejs.

NPM MIT CI PRs welcome!

Installation

# npm
npm install @coderosh/image-size
# yarn
yarn add @coderosh/image-size

Usage

  • Image source as url (nodejs and browser)

    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 }
    }
  • Image source as arraybuffer (nodejs and browser)

    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 }
    }
  • Image source as buffer (nodejs only)

    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 }
    }
  • Image source as blob (browser only)

    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 }
    }

License

MIT

About

Get height and width of image in node and browser

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

AltStyle によって変換されたページ (->オリジナル) /