img-type

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

Usage no npm install needed!

<script type="module">
  import imgType from 'https://cdn.skypack.dev/img-type';
</script>

README

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