From 299ae9bb6a84e178e742cceb20d87190e64653fc Mon Sep 17 00:00:00 2001 From: wulinsheng123 <409187100@qq.com> Date: Tue, 29 Nov 2022 03:27:39 +0800 Subject: [PATCH] fix bug: added a warning if the image was GIF (#5474) Co-authored-by: wuls --- .changeset/dirty-scissors-fail.md | 5 +++++ packages/integrations/image/src/vendor/squoosh/impl.ts | 4 ++++ 2 files changed, 9 insertions(+) create mode 100644 .changeset/dirty-scissors-fail.md diff --git a/.changeset/dirty-scissors-fail.md b/.changeset/dirty-scissors-fail.md new file mode 100644 index 0000000000..0ec7f4cdec --- /dev/null +++ b/.changeset/dirty-scissors-fail.md @@ -0,0 +1,5 @@ +--- +'@astrojs/image': minor +--- + +added a warning if the image was GIF diff --git a/packages/integrations/image/src/vendor/squoosh/impl.ts b/packages/integrations/image/src/vendor/squoosh/impl.ts index fa50c0fd96..3d01141d3e 100644 --- a/packages/integrations/image/src/vendor/squoosh/impl.ts +++ b/packages/integrations/image/src/vendor/squoosh/impl.ts @@ -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