インストール
npm install request-image-size
request-image-sizeで画像のディメンションを取得
const requestSize = require('request-image-size');
const imageUrl = 'https://dzone.com/storage/temp/3117491-web.png';
requestSize(imageUrl, (error, imageSize) => {
if (error) {
return null;
}
// 結果: {width: 1200, height: 630, type: 'png'}
return imageSize;
});
日本語を含む画像URLの場合、URLをエンコードする必要があると思います。
エンコードの為、querystring
ライブラリ(インストールしなくても良い)、またはJavascriptのencodeURI()
関数を使えます。