LoginSignup
1
1

More than 5 years have passed since last update.

nodeで画像のディメンションを取得する方法

Posted at

インストール
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()関数を使えます。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1