From 6da583cc374a24c7e96fefc6021720d41ace5eff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Mrowiec?= Date: Fri, 30 Jun 2023 16:38:23 +0200 Subject: [PATCH] Fix image metadata generation (#7510) * Fix problem where image metadata generation throwed error when provided url started with /@astroimage * Remove unnecessary changes --- .changeset/stupid-lions-relax.md | 5 +++++ packages/integrations/image/src/loaders/squoosh.ts | 8 +++++++- packages/integrations/image/src/utils/metadata.ts | 6 +++--- 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 .changeset/stupid-lions-relax.md diff --git a/.changeset/stupid-lions-relax.md b/.changeset/stupid-lions-relax.md new file mode 100644 index 0000000000000..07a6728a9f0de --- /dev/null +++ b/.changeset/stupid-lions-relax.md @@ -0,0 +1,5 @@ +--- +'@astrojs/image': patch +--- + +Fix problem where image metadata generation throwed error when provided url started with /@astroimage diff --git a/packages/integrations/image/src/loaders/squoosh.ts b/packages/integrations/image/src/loaders/squoosh.ts index e4ea530475df1..b91b05be0e38e 100644 --- a/packages/integrations/image/src/loaders/squoosh.ts +++ b/packages/integrations/image/src/loaders/squoosh.ts @@ -77,7 +77,13 @@ class SquooshService extends BaseSSRService { case 8: return { type: 'rotate', numRotations: 3 }; } - } catch {} + } catch { + error({ + level: 'info', + prefix: false, + message: red(`Cannot read metadata for ${transform.src}`), + }); + } } async transform(inputBuffer: Buffer, transform: TransformOptions) { diff --git a/packages/integrations/image/src/utils/metadata.ts b/packages/integrations/image/src/utils/metadata.ts index 6440be40d9bf9..7bb8afa417115 100644 --- a/packages/integrations/image/src/utils/metadata.ts +++ b/packages/integrations/image/src/utils/metadata.ts @@ -10,8 +10,7 @@ export interface Metadata extends ImageMetadata { export async function metadata(src: URL | string, data?: Buffer): Promise { const file = data || (await fs.readFile(src)); - - const { width, height, type, orientation } = await sizeOf(file); + const { width, height, type, orientation } = sizeOf(file); const isPortrait = (orientation || 0) >= 5; if (!width || !height || !type) { @@ -19,7 +18,8 @@ export async function metadata(src: URL | string, data?: Buffer): Promise