Promise to detect the image dimensions from a file via HTTP(S)


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

var httpImageSizePromise = require('http-image-size-promise');
.then(function(dimensions) {
  dimensions; //=> {width: 350, height: 150, type: 'gif'} 
.catch(function(reason) {

Use npm.

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

Check image-size-stream doc.

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

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) {
imageSize('').then(onFulfilled, onRejected);

Copyright (c) 2014 Shinnosuke Watanabe

Licensed under the MIT LIcense.