Giter Site home page Giter Site logo

request-image-size's Introduction

This fork contains the fix for FdezRomero#22. Some JPG images require more than one chunk to be properly analyzed so it shouldn't throw an error for a first chunk analysis.

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.

request-image-size's People

Contributors

fdezromero avatar pablopunk avatar dependabot[bot] avatar fbaiodias avatar jazmon avatar ryanscottaudio avatar bryantebeek avatar devgorilla avatar guvener avatar robpc avatar xdream86 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.