fix bug: added a warning if the image was GIF (#5474)

Co-authored-by: wuls <linsheng.wu@beantechs.com>
This commit is contained in:
wulinsheng123 2022-11-29 03:27:39 +08:00 committed by GitHub
parent f90a36873c
commit 299ae9bb6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'@astrojs/image': minor
---
added a warning if the image was GIF

View file

@ -31,6 +31,10 @@ export async function decodeBuffer(
const firstChunkString = Array.from(firstChunk)
.map((v) => String.fromCodePoint(v))
.join('')
// TODO (future PR): support more formats
if (firstChunkString.includes('GIF')) {
throw Error(`GIF images are not supported, please install the @astrojs/image/sharp plugin`)
}
const key = Object.entries(supportedFormats).find(([, { detectors }]) =>
detectors.some((detector) => detector.exec(firstChunkString))
)?.[0] as EncoderKey | undefined