Skip to content

Commit

Permalink
Handle EXIF orientation flag (#4021)
Browse files Browse the repository at this point in the history
* Handle EXIF orientation flag

* Create gentle-mails-mate.md
  • Loading branch information
delucis committed Jul 22, 2022
1 parent 3373181 commit 9aecf7c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-mails-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/image": patch
---

Handle EXIF orientation flag
7 changes: 4 additions & 3 deletions packages/integrations/image/src/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ 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;
}

return {
src,
width,
height,
width: isPortrait ? height : width,
height: isPortrait ? width : height,
format: type as InputFormat,
};
}

0 comments on commit 9aecf7c

Please sign in to comment.