- 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');
网友评论