A simple image type detector for nodejs, you can also test the type of file like isJpeg or isPng
npm install img-type
const imgType = require('img-type');
imgType.getType(currentFile).then((filetype) => {
console.log("IMG TYPE : " + filetype)
});
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
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
getType()
geTypeFromBuffer()
isJpeg()
isPng()
isGif()
isBmp()
isSvg()
isWebp()
isImg()
isRaw()
jpeg
png
gif
bmp
tiff
svg
webp
cr2
arw
crw
dng
More Supported files
New functions
MIT