read-image-size-promise
v1.0.0
Published
Promise to detect the image dimensions from a file
Downloads
10
Maintainers
Readme
read-image-size-promise
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
[](https:// www.npmjs.com/package/read-image-size-promise)
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.