Handle EXIF orientation flag (#4021)
* Handle EXIF orientation flag * Create gentle-mails-mate.md
This commit is contained in:
parent
337318142a
commit
9aecf7c7c7
2 changed files with 9 additions and 3 deletions
5
.changeset/gentle-mails-mate.md
Normal file
5
.changeset/gentle-mails-mate.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"@astrojs/image": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Handle EXIF orientation flag
|
|
@ -5,7 +5,8 @@ import { ImageMetadata, InputFormat } from './types';
|
||||||
export async function metadata(src: string): Promise<ImageMetadata | undefined> {
|
export async function metadata(src: string): Promise<ImageMetadata | undefined> {
|
||||||
const file = await fs.readFile(src);
|
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) {
|
if (!width || !height || !type) {
|
||||||
return undefined;
|
return undefined;
|
||||||
|
@ -13,8 +14,8 @@ export async function metadata(src: string): Promise<ImageMetadata | undefined>
|
||||||
|
|
||||||
return {
|
return {
|
||||||
src,
|
src,
|
||||||
width,
|
width: isPortrait ? height : width,
|
||||||
height,
|
height: isPortrait ? width : height,
|
||||||
format: type as InputFormat,
|
format: type as InputFormat,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue