summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/gentle-mails-mate.md5
-rw-r--r--packages/integrations/image/src/metadata.ts7
2 files changed, 9 insertions, 3 deletions
diff --git a/.changeset/gentle-mails-mate.md b/.changeset/gentle-mails-mate.md
new file mode 100644
index 000000000..eb3d561f2
--- /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 020d9461f..823862ea7 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<ImageMetadata | undefined> {
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<ImageMetadata | undefined>
return {
src,
- width,
- height,
+ width: isPortrait ? height : width,
+ height: isPortrait ? width : height,
format: type as InputFormat,
};
}