Skip to content

Commit 41b1437

Browse files
committed
Handle EXIF orientation flag
1 parent 476766b commit 41b1437

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

packages/integrations/image/src/metadata.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,17 @@ import { ImageMetadata, InputFormat } from './types';
55
export async function metadata(src: string): Promise<ImageMetadata | undefined> {
66
const file = await fs.readFile(src);
77

8-
const { width, height, type } = await sizeOf(file);
8+
const { width, height, type, orientation } = await sizeOf(file);
9+
const isPortrait = (orientation || 0) >= 5;
910

1011
if (!width || !height || !type) {
1112
return undefined;
1213
}
1314

1415
return {
1516
src,
16-
width,
17-
height,
17+
width: isPortrait ? height : width,
18+
height: isPortrait ? width : height,
1819
format: type as InputFormat,
1920
};
2021
}

0 commit comments

Comments
 (0)