advanced-cropper
Version:
The core of the advanced cropper libraries family
56 lines (51 loc) • 1.28 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var index = require('../../utils/index.js');
var imageMimes = [
{
format: 'image/png',
pattern: [0x89, 0x50, 0x4e, 0x47],
},
{
format: 'image/jpeg',
pattern: [0xff, 0xd8, 0xff],
},
{
format: 'image/gif',
pattern: [0x47, 0x49, 0x46, 0x38],
},
{
format: 'image/webp',
pattern: [
0x52,
0x49,
0x46,
0x46,
undefined,
undefined,
undefined,
undefined,
0x57,
0x45,
0x42,
0x50,
0x56,
0x50,
],
},
];
function getMimeType(data, fallback) {
if (fallback === void 0) { fallback = null; }
var mimeType = fallback;
if (index.isArrayBufferLike(data)) {
var byteArray_1 = new Uint8Array(data).subarray(0, 4);
var candidate = imageMimes.find(function (el) { return el.pattern.every(function (p, i) { return !p || byteArray_1[i] === p; }); });
if (candidate) {
mimeType = candidate.format;
}
}
if (mimeType) {
return mimeType;
}
}
exports.getMimeType = getMimeType;