UNPKG

image-size

Version:

get dimensions of any image file

23 lines (22 loc) • 565 B
import { typeHandlers, types } from './types/index.js'; const firstBytes = new Map([ [0x00, 'heif'], [0x38, 'psd'], [0x42, 'bmp'], [0x44, 'dds'], [0x47, 'gif'], [0x49, 'tiff'], [0x4d, 'tiff'], [0x52, 'webp'], [0x69, 'icns'], [0x89, 'png'], [0xff, 'jpg'], ]); export function detector(input) { const byte = input[0]; const type = firstBytes.get(byte); if (type && typeHandlers.get(type)?.validate(input)) { return type; } return types.find((type) => typeHandlers.get(type)?.validate(input)); }