Get the width and height of an image in node.js

前端 未结 5 1711
有刺的猬
有刺的猬 2020-12-23 15:58

Is it possible to get the width and height of an image in node.js (on the server side, not the client side)? I need to find the width and height of an image in a node.js lib

5条回答
  •  一整个雨季
    2020-12-23 16:59

    Installing GraphicsMagick or ImageMagick isn't at all needed, determining the dimensions of a image is as easy as looking at the header. image-size is a pure javascript implementation of said feature which is very easy to use.

    https://github.com/netroy/image-size

    var sizeOf = require('image-size');
    sizeOf('images/funny-cats.png', function (err, dimensions) {
      console.log(dimensions.width, dimensions.height);
    });
    

提交回复
热议问题