@kqtec/http-image-size-promise

1.3.0 • Public • Published

http-image-size-promise

Build Status Build status Coverage Status Dependency Status devDependency Status

Promise to detect the dimensions of an image file via HTTP(S), using image-size-stream

var httpImageSizePromise = require('http-image-size-promise');

httpImageSizePromise('http://placehold.it/350x150')
.then(function(dimensions) {
  dimensions; //=> {width: 350, height: 150, type: 'gif'}
})
.catch(function(reason) {
  console.warn(reason);
});

Installation

NPM version

Use npm.

npm install --save http-image-size-promise

Supported image formats

Check image-size-stream doc.

API

var httpImageSizePromise = require('http-image-size-promise');

httpImageSizePromise(imageFileUrl [, options])

imageFileUrl: String (URL) or Object (parsed URL object)
options: Object (directly passed to the got options and the image-size-stream option)
Return: Object (Promise)

It gets an image file via got module.

When it detects the width and height of the image, it will be fulfilled with an object in the form {width: [Number], height: [Number], type: [String]} as an argument of callback.

type will be one of the following strings: bmp gif jpg png psd svg tiff webp

When it fails to get the file or the file is not supported, it will be rejected with an error as an argument of callback.

var imageSize = httpImageSizePromise();

var onFulfilled = function(dimensions) {
  console.log('Size: ' + dimensions.width + ' x ' + dimensions.height);
  console.log('Type: ' + dimensions.type);
};

var onRejected = function(reason) {
  console.warn(reason);
};

imageSize('https://url.to/image.jpg').then(onFulfilled, onRejected);

License

Copyright (c) 2014 Shinnosuke Watanabe

Licensed under the MIT LIcense.

Package Sidebar

Install

npm i @kqtec/http-image-size-promise

Weekly Downloads

0

Version

1.3.0

License

MIT

Unpacked Size

7.37 kB

Total Files

4

Last publish

Collaborators

  • zhch92