image-type识别图片真实类型

2019-05-30  本文已影响0人  AsaGuo
  1. Install
npm install --save image-type
npm install read-chunk
  1. Usage
let readChunk = require('read-chunk');
let imageType = require('image-type');

let image_path = 'avatar.png'
let buffer = readChunk.sync(image_path, 0, image_path.length);
let image_type = imageType(buffer);

if (image_type)
   //=> {ext: 'png', mime: 'image/png'}
   console.log('avatar.png is an image');
else
   console.log('avatar.png is not an image');

上一篇 下一篇

猜你喜欢

热点阅读