@kqtec/http-image-size-promise v1.3.0
http-image-size-promise
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 install --save http-image-size-promiseSupported 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.