read-image-size-promise

1.0.0 • Public • Published

read-image-size-promise

Build Status Build status Coverage Status Dependency Status devDependency Status

Promise to detect the image dimensions from a file, using image-size-stream

//       +-----------+
//       |           |
// 240px |  foo.jpg  |
//       |           |
//       +-----------+
//           320px 
 
var readImageSizePromise = require('read-image-size-promise');
 
readImageSizePromise('path/to/foo.jpg')
.then(function(dimensions) {
  dimensions; //=> {width: 320, height: 240, type: 'jpg'}
})
.catch(function(reason) {
  console.warn(reason);
});

Installation

NPM version

Use npm.

npm install read-image-size-promise

Supported image formats

Check image-size-stream doc.

API

var readImageSizePromise = require('read-image-size-promise');

readImageSizePromise(imageFilePath [, options])

imageFilePath: String (local file path)
options: String (directly passed to fs.createWriteStream options and image-size-stream option)
Return: Object (Promise)

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

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

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

var imageSize = readImageSizePromise();
 
var onFulfilled = function(dimensions) {
  console.log('Size: ' + dimensions.width + ' x ' + dimensions.height);
};
 
var onRejected = function(reason) {
  console.warn(reason.message);
};
 
imageSize('path/to/image.png').then(onFulfilled, onRejected);

License

Copyright (c) 2014 Shinnosuke Watanabe

Licensed under the MIT LIcense.

Package Sidebar

Install

npm i read-image-size-promise

Weekly Downloads

2

Version

1.0.0

License

none

Last publish

Collaborators

  • shinnn