https://github.com/coderosh/image-size
Get height and width of image in node and browser
https://github.com/coderosh/image-size
image image-size isomorphic
Last synced: 6 months ago
JSON representation
Get height and width of image in node and browser
- Host: GitHub
- URL: https://github.com/coderosh/image-size
- Owner: coderosh
- License: mit
- Created: 2021-10-26T15:52:26.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-10T02:33:28.000Z (almost 4 years ago)
- Last Synced: 2025-04-06T15:47:56.650Z (9 months ago)
- Topics: image, image-size, isomorphic
- Language: TypeScript
- Homepage: https://coderosh.github.io/image-size/
- Size: 91.8 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# image-size
> Get height and width of image using [Image](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/Image) api in browser and [buffer-image-size](https://npmjs.com/package/buffer-image-size) package in nodejs.
## Installation
```sh
# npm
npm install @coderosh/image-size
# yarn
yarn add @coderosh/image-size
```
## Usage
- Image source as url (nodejs and browser)
```js
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)
```js
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)
```js
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)
```js
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