jojo/models/user
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
..
fixtures refactor: migrate from lib/pq to jackc/pgx (#10219) 2025-11-30 17:47:45 +01:00
activitypub.go Improved signature handling & instance actor (#8275) 2025-07-01 19:49:00 +02:00
avatar.go feat: serve downsized versions of avatars (#11242) 2026-05-16 12:04:05 +02:00
avatar_test.go feat: serve downsized versions of avatars (#11242) 2026-05-16 12:04:05 +02:00
badge.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
block.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
block_test.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
email_address.go refactor: replace Value() from Option[T] with Get() & ValueOrZeroValue() (#11218) 2026-02-10 16:41:21 +01:00
email_address_test.go chore: add modernizer linter (#11936) 2026-04-02 03:29:37 +02:00
error.go chore(federation): re-enable nilnil lint (#11253) 2026-04-13 22:05:29 +02:00
external_login_user.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
federated_user.go feat: Follow remote users; feed tab (#10380) 2026-04-12 03:31:03 +02:00
federated_user_follower.go Federated user activity following: Isolated model changes (#8078) 2025-06-21 12:02:58 +02:00
federated_user_follower_test.go Federated user activity following: Isolated model changes (#8078) 2025-06-21 12:02:58 +02:00
federated_user_test.go Federated user activity following: Isolated model changes (#8078) 2025-06-21 12:02:58 +02:00
follow.go fix: assorted ActivityPub code only refactors (#8708) 2025-07-28 15:17:29 +02:00
follow_test.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
list.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
main_test.go chore: move all test blank imports in a single package (#10662) 2026-01-02 05:32:32 +01:00
moderation.go chore: make use of go1.26 features (#12369) 2026-05-01 22:51:48 +02:00
moderation_test.go feat: Admin interface for abuse reports (#7905) 2025-07-23 00:20:15 +02:00
must_change_password.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
openid.go fix: do 2FA on OpenID connect 2025-08-30 09:41:20 +02:00
openid_test.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
redirect.go fix: do visibility check for user redirect lookup 2025-08-30 09:37:25 +02:00
search.go refactor: replace Value() from Option[T] with Get() & ValueOrZeroValue() (#11218) 2026-02-10 16:41:21 +01:00
setting.go chore(cleanup): replaces unnecessary calls to formatting functions by non-formatting equivalents (#7994) 2025-05-29 17:34:29 +02:00
setting_keys.go Add codespell support and fix a good number of typos with its help (#3270) 2024-05-09 13:49:37 +00:00
setting_test.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
user.go feat: persist OAuth2/OIDC sign-in via IdP re-validation (#12321) 2026-05-15 02:31:20 +02:00
user_repository.go chore(federation): re-enable nilnil lint (#11253) 2026-04-13 22:05:29 +02:00
user_system.go fix: only send Forgejo Actions notifications to one user (#8227) 2025-06-21 12:15:38 +02:00
user_test.go feat: persist OAuth2/OIDC sign-in via IdP re-validation (#12321) 2026-05-15 02:31:20 +02:00
user_update.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00