Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fdezromero/request-image-size
Detect image dimensions via request.
https://github.com/fdezromero/request-image-size
detect dimension height image javascript nodejs probe promise request resolution size width
Last synced: 2 months ago
JSON representation
Detect image dimensions via request.
- Host: GitHub
- URL: https://github.com/fdezromero/request-image-size
- Owner: FdezRomero
- Created: 2014-07-23T18:50:39.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2022-12-09T23:06:36.000Z (about 2 years ago)
- Last Synced: 2024-04-14T19:40:42.247Z (9 months ago)
- Topics: detect, dimension, height, image, javascript, nodejs, probe, promise, request, resolution, size, width
- Language: JavaScript
- Size: 146 KB
- Stars: 39
- Watchers: 7
- Forks: 16
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# request-image-size
[![NPM](https://nodei.co/npm/request-image-size.png)](https://nodei.co/npm/request-image-size/)
Detects image dimensions via [request](https://github.com/request/request) instead of Node.js native `http`/`https`, allowing for options and following redirects by default. It reduces network traffic by aborting requests as soon as [image-size](https://github.com/image-size/image-size) is able to obtain the image size.
Since version 2.0.0 it returns an ES6 native `Promise` that resolves with the `size` object or rejects with an `Error`. Requires Node.js v4+.
If you prefer using a callback, please use version 1.3.0 instead ([docs](CHANGELOG.md))
Supports all the image formats supported by [image-size](https://github.com/image-size/image-size):
- BMP
- CUR
- GIF
- ICO
- JPEG
- PNG
- PSD
- TIFF
- WebP
- SVG
- DDS### Dependencies
- [request](https://github.com/request/request)
- [image-size](https://github.com/image-size/image-size)
- [standard-http-error](https://github.com/moll/js-standard-http-error)## Basic usage
```js
const requestImageSize = require('request-image-size');requestImageSize('http://nodejs.org/images/logo.png')
.then(size => console.log(size))
.catch(err => console.error(err));
```Result:
```js
{ width: 245, height: 66, type: 'png', downloaded: 856 }
```## Advanced usage
Specifying a request `options` object ([docs](https://github.com/request/request/#requestoptions-callback)):
```js
const requestImageSize = require('request-image-size');const options = {
url: 'http://nodejs.org/images/logo.png',
headers: {
'User-Agent': 'request-image-size'
}
};requestImageSize(options)
.then(size => console.log(size))
.catch(err => console.error(err));
```## License
Copyright (c) 2017 Rodrigo Fernández Romero
Licensed under the MIT license.
Based on [http-image-size](https://github.com/jo/http-image-size) from Johannes J. Schmidt.