按常见图片容器的 magic bytes 推断图片格式。
这个函数只看文件头,不依赖 URL 后缀或 Content-Type,适合在上传、复制、下载后复核真实文件格式。
Content-Type
待检查的字节序列,可以是 Uint8Array、Buffer 或普通数字数组。
Uint8Array
Buffer
识别到的图片格式;无法识别时返回 null。
null
0.2.0
detectImageFileFormat(new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10])) // 'png'detectImageFileFormat(new Uint8Array([1, 2, 3])) // null Copy
detectImageFileFormat(new Uint8Array([137, 80, 78, 71, 13, 10, 26, 10])) // 'png'detectImageFileFormat(new Uint8Array([1, 2, 3])) // null
按常见图片容器的 magic bytes 推断图片格式。
这个函数只看文件头,不依赖 URL 后缀或
Content-Type,适合在上传、复制、下载后复核真实文件格式。