Skip to content

Commit

Permalink
Fix thumbnail's orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Dec 18, 2024
1 parent db5762b commit 4fc6d9d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Version 0.3.2

To be released.

- Fixed a bug where generated thumbnails had not copied the EXIF orientation
metadata from the original image. [[#76]]

[#76]: https://github.com/dahlia/hollo/issues/76


Version 0.3.1
-------------
Expand Down
21 changes: 15 additions & 6 deletions src/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@ export async function uploadThumbnail(
thumbnailArea = DEFAULT_THUMBNAIL_AREA,
): Promise<Thumbnail> {
const originalMetadata = await original.metadata();
const thumbnailSize = calculateThumbnailSize(
originalMetadata.width!,
originalMetadata.height!,
thumbnailArea,
);
const thumbnail = await original.resize(thumbnailSize).webp().toBuffer();
let width = originalMetadata.width!;
let height = originalMetadata.height!;
if (originalMetadata.orientation !== 1) {
// biome-ignore lint/style/noParameterAssign:
original = original.clone();
original.rotate();
if (originalMetadata.orientation !== 3) {
[width, height] = [height, width];
}
}
const thumbnailSize = calculateThumbnailSize(width, height, thumbnailArea);
const thumbnail = await original
.resize(thumbnailSize)
.webp({ nearLossless: true })
.toBuffer();
const content = new Uint8Array(thumbnail);
try {
await disk.put(`media/${id}/thumbnail.webp`, content, {
Expand Down

0 comments on commit 4fc6d9d

Please sign in to comment.