diff --git a/.changeset/gentle-mails-mate.md b/.changeset/gentle-mails-mate.md new file mode 100644 index 000000000000..eb3d561f229a --- /dev/null +++ b/.changeset/gentle-mails-mate.md @@ -0,0 +1,5 @@ +--- +"@astrojs/image": patch +--- + +Handle EXIF orientation flag diff --git a/packages/integrations/image/src/metadata.ts b/packages/integrations/image/src/metadata.ts index 020d9461fdc3..823862ea7938 100644 --- a/packages/integrations/image/src/metadata.ts +++ b/packages/integrations/image/src/metadata.ts @@ -5,7 +5,8 @@ import { ImageMetadata, InputFormat } from './types'; export async function metadata(src: string): Promise { const file = await fs.readFile(src); - const { width, height, type } = await sizeOf(file); + const { width, height, type, orientation } = await sizeOf(file); + const isPortrait = (orientation || 0) >= 5; if (!width || !height || !type) { return undefined; @@ -13,8 +14,8 @@ export async function metadata(src: string): Promise return { src, - width, - height, + width: isPortrait ? height : width, + height: isPortrait ? width : height, format: type as InputFormat, }; }