Skip to content

Commit

Permalink
Fix thumbnail's orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia authored and 0marSalah committed Dec 18, 2024
1 parent 952fbe9 commit cdf4e4c
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,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) {

This comment has been minimized.

Copy link
@aliceif

aliceif Dec 19, 2024

I wonder if orientation can somehow be null or something?

// 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 cdf4e4c

Please sign in to comment.