@zerodeps/image-probe
v0.2.0
Published
Get image type and size from the first bytes, without needing to read or download it in full ... And without any NPM additional dependencies!
Downloads
1,434
Maintainers
Readme
image-probe
Get image format and dimensions quickly and efficiently. Without any single additional dependency!
Installation
npm install --save @zerodeps/image-probe
Usage
import { ImageProbe } from "@zerodeps/image-probe";
const buffer = readFileSync("image.jpg");
const results = ImageProbe.fromBuffer(buffer);
if (results === undefined) {
// NOT AN IMAGE!!!
} else {
/* results contains:
{
type: "jpeg",
mimeType: "image/jpeg",
width: 512,
height: 256
}
*/
}
Supported image type formats
| Image Format | Type | MIME Type | | ------------ | ---- | ---------- | | JPEG | jpeg | image/jpeg | | JPEG 2000 | jp2 | image/jp2 | | GIF (87a) | gif | image/gif | | GIF (89a) | gif | image/gif | | PNG | png | image/png | | PNG (IHDR) | png | image/png | | WEBP (VP8) | webp | image/webp | | WEBP (VP8L) | webp | image/webp | | WEBP (VP8X) | webp | image/webp | | BMP | bmp | image/bmp |