Handle EXIF orientation flag (#4021)

* Handle EXIF orientation flag

* Create gentle-mails-mate.md
This commit is contained in:
Chris Swithinbank 2022-07-22 21:14:00 +02:00 committed by GitHub
parent 337318142a
commit 9aecf7c7c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
"@astrojs/image": patch
---
Handle EXIF orientation flag

View file

@ -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,
};
}