[PR #2147] [MERGED] feat(server): enhanced thumbnails generation code #9403

Closed
opened 2026-02-05 14:04:06 +03:00 by OVERLORD · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/immich-app/immich/pull/2147
Author: @brighteyed
Created: 4/2/2023
Status: Merged
Merged: 4/4/2023
Merged by: @alextran1502

Base: mainHead: enhance-thumbnails-generation


📝 Commits (2)

  • 2729ee7 Add size parameter to extractVideoThumbnail
  • 7593eba Ensure minimum dimension of webp thumbnail

📊 Changes

4 files changed (+19 additions, -6 deletions)

View changed files

📝 server/libs/domain/src/media/media.repository.ts (+1 -1)
📝 server/libs/domain/src/media/media.service.spec.ts (+1 -0)
📝 server/libs/domain/src/media/media.service.ts (+6 -2)
📝 server/libs/infra/src/repositories/media.repository.ts (+11 -3)

📄 Description

This PR implements the following enhancements of the thumbnail generation code.

Video thumbnails

Immich now uses outside mode to generate JPEG thumbnails to make them as small as possible while ensuring their dimensions are greater or equal than 1440. There is an exception for smaller images that are not enlarged.

I've noticed that the algorithm is not the same for video files (Immich saves the video frame in its original resolution as a JPEG thumbnail). I've added an option for ffmpeg inside extractVideoThumbnail to implement the same behavior for videos.

For example:

  • For 4K videos (3840x2160), a JPEG thumbnail size now equals to 2560x1440 instead of 3840x2160
  • For 1920x1080 videos, a JPEG thumbnail size equals to the original resolution (1920x1080)

WEBP thumbnails dimensions

All WEBP thumbnails are being generated to fit inside 250x250 rectangle. For example, for 1920x1080 video, the size of the generated WEBP thumbnail is 250x141. Afterward that small image is being enlarged by the browser (in the case of a web client) to make its size at least 235 thus additionally loosing visual quality.

I've changed the mode to outside that resizes the image to be as small as possible while ensuring its dimensions are greater than or equal to 250.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/immich-app/immich/pull/2147 **Author:** [@brighteyed](https://github.com/brighteyed) **Created:** 4/2/2023 **Status:** ✅ Merged **Merged:** 4/4/2023 **Merged by:** [@alextran1502](https://github.com/alextran1502) **Base:** `main` ← **Head:** `enhance-thumbnails-generation` --- ### 📝 Commits (2) - [`2729ee7`](https://github.com/immich-app/immich/commit/2729ee7df816253bfd69de2cf8cfbd20e2540cfb) Add size parameter to extractVideoThumbnail - [`7593eba`](https://github.com/immich-app/immich/commit/7593eba3864eb150109f047b68ad812e21c76134) Ensure minimum dimension of webp thumbnail ### 📊 Changes **4 files changed** (+19 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `server/libs/domain/src/media/media.repository.ts` (+1 -1) 📝 `server/libs/domain/src/media/media.service.spec.ts` (+1 -0) 📝 `server/libs/domain/src/media/media.service.ts` (+6 -2) 📝 `server/libs/infra/src/repositories/media.repository.ts` (+11 -3) </details> ### 📄 Description This PR implements the following enhancements of the thumbnail generation code. ## Video thumbnails Immich now uses `outside` mode to generate JPEG thumbnails to make them as small as possible while ensuring their dimensions are greater or equal than 1440. There is an exception for smaller images that are not enlarged. I've noticed that the algorithm is not the same for video files (Immich saves the video frame in its original resolution as a JPEG thumbnail). I've added an option for ffmpeg inside `extractVideoThumbnail` to implement the same behavior for videos. For example: - For 4K videos (3840x2160), a JPEG thumbnail size now equals to 2560x1440 instead of 3840x2160 - For 1920x1080 videos, a JPEG thumbnail size equals to the original resolution (1920x1080) ## WEBP thumbnails dimensions All WEBP thumbnails are being generated to fit inside 250x250 rectangle. For example, for 1920x1080 video, the size of the generated WEBP thumbnail is 250x141. Afterward that small image is being enlarged by the browser (in the case of a web client) to make its size at least 235 thus additionally loosing visual quality. I've changed the mode to `outside` that resizes the image to be as small as possible while ensuring its dimensions are greater than or equal to 250. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
OVERLORD added the pull-request label 2026-02-05 14:04:06 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: immich-app/immich#9403