summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Chris Swithinbank <swithinbank@gmail.com> 2022-07-22 21:14:00 +0200
committerGravatar GitHub <noreply@github.com> 2022-07-22 19:14:00 +0000
commit9aecf7c7c7211f34236d8dde624ca388310d3727 (patch)
tree40166f5e94c3dca06ecde7a68b44ec963fd45b76
parent337318142a1ff7f9ec358d61833728c865ef427f (diff)
downloadastro-9aecf7c7c7211f34236d8dde624ca388310d3727.tar.gz
astro-9aecf7c7c7211f34236d8dde624ca388310d3727.tar.zst
astro-9aecf7c7c7211f34236d8dde624ca388310d3727.zip
Handle EXIF orientation flag (#4021)
* Handle EXIF orientation flag * Create gentle-mails-mate.md
-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,
};
}