forgejo/modules/repository
Antonin Delpeuch 0a57672544 feat: serve downsized versions of avatars (#11242)
Fixes #2325.

This introduces a way to download downsized versions of the user and repository avatars:
* `/avatars/123abcd` still serves the full-size avatar
* `/avatars/123abcd?size=64` serves it at size 64x64 px

Those downsized versions are computed on demand when requested for the first time and cached. The caching is done in a storage location configurable in the instance settings, just like the storage locations for the full-sized avatars are. The sizes of the downsized images are restricted to a fixed set of sizes, so that the cache doesn't grow too big. The caching and resizing logic is exposed in a way that could potentially be reused for other types of images (such as user uploads in issue discussions).

Luckily, the Go templates already specify in many places which size those avatars should be rendered, even if this information was only used for external avatar providers (such as Gravatar) until now.

The range of sizes requested by the HTML templates is rather wide: the table below lists all the sizes I could find, and the corresponding size served by the backend with the logic I implemented. The scaling factor of 2 was already used for requesting resized external avatars, and likely exists to make sure that users with display scaling enabled get a sharper picture.

| Size requested in the template | After scaling (x2)  | Size of the image served |
|---------|---------|---------|
| 256 px |  512 px | original (512 px) |
| 140 px | 280 px | original (512 px) |
| 48 px | 96 px | 128 px |
| 40 px | 80 px | 128 px |
| 32 px | 64 px | 64 px |
| 28 px | 56 px | 64 px |
| 24 px | 48 px | 64 px |
| 20 px | 40 px | 64 px |

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11242
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
2026-05-16 12:04:05 +02:00
..
branch.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
branch_test.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
collaborator.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
collaborator_test.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
commits.go Show if commit is signed in activity feed and unify sha box (#6933) 2025-05-03 10:54:52 +00:00
commits_test.go feat: serve downsized versions of avatars (#11242) 2026-05-16 12:04:05 +02:00
create.go feat: configurable default units for mirrors (#7902) 2025-06-03 08:12:29 +02:00
create_test.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
delete.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
env.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
fork.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
init.go feat: replace repo based server-side hooks with centralised hooks (#10397) 2026-04-27 22:34:46 +02:00
init_test.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
license.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
license_test.go chore: update license test (#11485) 2026-03-04 16:16:12 +01:00
main_test.go chore: move all test blank imports in a single package (#10662) 2026-01-02 05:32:32 +01:00
push.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
repo.go fix: set tag message on tag addition (#9913) 2025-10-31 07:04:28 +01:00
repo_test.go fix: set tag message on tag addition (#9913) 2025-10-31 07:04:28 +01:00
temp.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00