diff --git a/.changeset/stupid-lions-relax.md b/.changeset/stupid-lions-relax.md new file mode 100644 index 000000000000..07a6728a9f0d --- /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 e4ea530475df..b91b05be0e38 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 6440be40d9bf..7bb8afa41711 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