Norse Polytheistic Mythology
    Wondering what’s next for npm?Check out our public roadmap! »

    img-type

    0.1.16 • Public • Published

    img-type

    A simple image type detector for nodejs, you can also test the type of file like isJpeg or isPng

    Build Status

    Installation

    npm install img-type

    Usage

    Node.js From file
    const imgType = require('img-type');
     
    imgType.getType(currentFile).then((filetype) => {
        console.log("IMG TYPE : " + filetype)
    });
    Node.js From buffer
    const imgType = require('img-type');
     
    //some code to get a buffer fs.readFile or read-chunk for exemple
    var filetype = imgType.getTypeFromBuffer(buffer);
     
    console.log("IMG TYPE : " + filetype);

    For a jpeg file output should be IMG TYPE : jpeg

    For a non supported file type output should be IMG TYPE : false

    Node.js file test by type
    const imgType = require('img-type');
     
    //Exemple : currentFileJpeg = ./test.jpg
    imgType.isJpeg(currentFileJpeg).then((isJpeg) => {
        console.log("IS JPEG : " + isJpeg)
    });

    For a jpeg file output should be IS JPEG : true

    For all other file output should be IS JPEG : false

    Functions availables

    getType()
    geTypeFromBuffer()
    isJpeg()
    isPng()
    isGif()
    isBmp()
    isSvg()
    isWebp() isImg() isRaw()

    Supported file types

    Basic file types

    jpeg
    png
    gif
    bmp
    tiff
    svg
    webp

    Raw file types

    cr2
    arw
    crw
    dng

    Comming Soon

    More Supported files

    New functions

    License

    MIT

    Install

    npm i img-type

    DownloadsWeekly Downloads

    41

    Version

    0.1.16

    License

    MIT

    Unpacked Size

    10.9 kB

    Total Files

    4

    Last publish

    Collaborators

    • avatar