New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@coderosh/image-size

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@coderosh/image-size

Get height and width of image in node and browser

latest
Source
npmnpm
Version
2.0.1
Version published
Maintainers
1
Created
Source

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

Keywords

image-size

FAQs

Package last updated on 10 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts