README
react-image-size
A JavaScript module to get size (dimensions) of any image file by url
Programmatic Usage
npm install react-image-size --save
or
yarn add react-image-size
Async/Await
import reactImageSize from 'react-image-size';
try {
const { width, height } = await reactImageSize(imageUrl);
...
} catch {
...
}
Using promises
import reactImageSize from 'react-image-size';
reactImageSize(imageUrl)
.then(({ width, height }) => ...)
.catch((errorMessage) => ...);
With reject timer
import reactImageSize from 'react-image-size';
const rejectTimeout = 5000; // ms
try {
const { width, height } = await reactImageSize(imageUrl, rejectTimeout);
...
} catch (errorMessage) {
// if request takes longer than 5 seconds an timeout exception will be thrown
}