in source/image-handler/image-request.ts [384:407]
public inferImageType(imageBuffer: Buffer): string {
const imageSignature = imageBuffer.slice(0, 4).toString('hex').toUpperCase();
switch (imageSignature) {
case '89504E47':
return 'image/png';
case 'FFD8FFDB':
case 'FFD8FFE0':
case 'FFD8FFEE':
case 'FFD8FFE1':
return 'image/jpeg';
case '52494646':
return 'image/webp';
case '49492A00':
return 'image/tiff';
case '4D4D002A':
return 'image/tiff';
default:
throw new ImageHandlerError(
StatusCodes.INTERNAL_SERVER_ERROR,
'RequestTypeError',
'The file does not have an extension and the file type could not be inferred. Please ensure that your original image is of a supported file type (jpg, png, tiff, webp, svg). Refer to the documentation for additional guidance on forming image requests.'
);
}
}