UNPKG

image-type

Version:

Detect the image type of an ArrayBuffer/Uint8Array

31 lines (27 loc) 449 B
import {fileTypeFromBuffer} from 'file-type'; const imageExtensions = new Set([ 'jpg', 'png', 'gif', 'webp', 'flif', 'cr2', 'tif', 'bmp', 'jxr', 'psd', 'ico', 'bpg', 'jp2', 'jpm', 'jpx', 'heic', 'cur', 'dcm', 'avif', ]); export default async function imageType(input) { const result = await fileTypeFromBuffer(input); return result && imageExtensions.has(result.ext) ? result : undefined; } export const minimumBytes = 4100;