美文网首页
image-type识别图片真实类型

image-type识别图片真实类型

作者: AsaGuo | 来源:发表于2019-05-30 14:54 被阅读0次
    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');
    
    

    相关文章

      网友评论

          本文标题:image-type识别图片真实类型

          本文链接:https://www.haomeiwen.com/subject/cbqvtctx.html