Get image type and size from the first bytes, without needing to read or download it in full ... And without any NPM additional dependencies!
npm install @zerodeps/image-probeGet image format and dimensions quickly and efficiently. Without any single additional dependency!
npm install --save @zerodeps/image-probe
``typescript
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
}
*/
}
``
| 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 |