npm

Join us for the upcoming webinar, "Enterprise JavaScript done right: the tools you love, the security you need."Sign up here »

img-type

0.1.13 • 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()

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

31

version

0.1.13

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability