ris

request-image-size

Detect image dimensions via request.

Showing:

Popularity

Downloads/wk

4.6K

GitHub Stars

33

Maintenance

Last Commit

5mos ago

Contributors

9

Package

Dependencies

3

Size (min+gzip)

196.0KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

request-image-size

NPM

Detects image dimensions via 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 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)

Supports all the image formats supported by image-size:

  • BMP
  • CUR
  • GIF
  • ICO
  • JPEG
  • PNG
  • PSD
  • TIFF
  • WebP
  • SVG
  • DDS

Dependencies

Basic usage

const requestImageSize = require('request-image-size');

requestImageSize('http://nodejs.org/images/logo.png')
.then(size => console.log(size))
.catch(err => console.error(err));

Result:

{ width: 245, height: 66, type: 'png', downloaded: 856 }

Advanced usage

Specifying a request options object (docs):

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 from Johannes J. Schmidt.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial