chore: add detection for image more types (#67112)
These image types aren't optimized but we can still detect them to bypass optimization earlier.
This commit is contained in:
parent
f9ea3a89f1
commit
f5d616b77e
4 changed files with 16 additions and 0 deletions
|
@ -32,6 +32,8 @@ const JPEG = 'image/jpeg'
|
|||
const GIF = 'image/gif'
|
||||
const SVG = 'image/svg+xml'
|
||||
const ICO = 'image/x-icon'
|
||||
const TIFF = 'image/tiff'
|
||||
const BMP = 'image/bmp'
|
||||
const CACHE_VERSION = 3
|
||||
const ANIMATABLE_TYPES = [WEBP, PNG, GIF]
|
||||
const VECTOR_TYPES = [SVG]
|
||||
|
@ -158,6 +160,12 @@ export function detectContentType(buffer: Buffer) {
|
|||
if ([0x00, 0x00, 0x01, 0x00].every((b, i) => buffer[i] === b)) {
|
||||
return ICO
|
||||
}
|
||||
if ([0x49, 0x49, 0x2a, 0x00].every((b, i) => buffer[i] === b)) {
|
||||
return TIFF
|
||||
}
|
||||
if ([0x42, 0x4d].every((b, i) => buffer[i] === b)) {
|
||||
return BMP
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
|
|
|
@ -34,4 +34,12 @@ describe('detectContentType', () => {
|
|||
const buffer = await getImage('./images/test.ico')
|
||||
expect(detectContentType(buffer)).toBe('image/x-icon')
|
||||
})
|
||||
it('should return tiff', async () => {
|
||||
const buffer = await getImage('./images/test.tiff')
|
||||
expect(detectContentType(buffer)).toBe('image/tiff')
|
||||
})
|
||||
it('should return bmp', async () => {
|
||||
const buffer = await getImage('./images/test.bmp')
|
||||
expect(detectContentType(buffer)).toBe('image/bmp')
|
||||
})
|
||||
})
|
||||
|
|
BIN
test/unit/image-optimizer/images/test.bmp
Normal file
BIN
test/unit/image-optimizer/images/test.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 79 KiB |
BIN
test/unit/image-optimizer/images/test.tiff
Normal file
BIN
test/unit/image-optimizer/images/test.tiff
Normal file
Binary file not shown.
Loading…
Reference in a new issue