image-type识别图片真实类型
2019-05-30 本文已影响0人
AsaGuo
- Install
npm install --save image-type
npm install read-chunk
- 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');