Media preview proxy: image previews in configured sizes, optionally AVIF #7997

Open
lambadalambda wants to merge 3 commits from lambadalambda/pleroma:feature/media-preview-sizes into develop

Image previews in a few fixed sizes between the thumbnail and the original, so clients can show an image that fits the screen instead of a possibly huge original; optionally as AVIF.

  • /proxy/preview/…?size=N resizes to a box of N px (long side, libvips, never upscales). N must be one of :media_preview_proxy, :image_sizes (default [960, 1600, 2560]), compared as written; anything else redirects to the thumbnail, so arbitrary values cannot add resizes or cache entries. Nothing is stored; a cache in front of /proxy keeps the sizes.
  • Image attachments get pleroma.image_sizes: [%{size, url, width?, height?}]: the sizes smaller than the image (all of them when its dimensions are unknown), with approximate dimensions. Not for GIF/APNG, and only with the preview proxy enabled. Clients can use them as a srcset and keep url for the original.
  • AVIF (:avif, off by default; :avif_quality 55, :avif_effort 3): the sizes go out as AVIF to clients whose Accept has image/avif, with Vary: Accept; about 40% smaller than JPEG q70 at the same SSIM, ~0.7 s to encode a 1600 px image on a small VPS (JPEG: 0.14 s). Needs a libvips with libheif and an AV1 encoder; without it, or when an encode fails, the sizes stay JPEG/PNG. Thumbnails stay JPEG/PNG. The Docker image adds vips-heif (build and runtime stage: Vix makes its functions from what libvips offers at compile time).
  • Config description, cheatsheet, API schema and changelog updated.
Image previews in a few fixed sizes between the thumbnail and the original, so clients can show an image that fits the screen instead of a possibly huge original; optionally as AVIF. - `/proxy/preview/…?size=N` resizes to a box of N px (long side, libvips, never upscales). N must be one of `:media_preview_proxy, :image_sizes` (default `[960, 1600, 2560]`), compared as written; anything else redirects to the thumbnail, so arbitrary values cannot add resizes or cache entries. Nothing is stored; a cache in front of `/proxy` keeps the sizes. - Image attachments get `pleroma.image_sizes: [%{size, url, width?, height?}]`: the sizes smaller than the image (all of them when its dimensions are unknown), with approximate dimensions. Not for GIF/APNG, and only with the preview proxy enabled. Clients can use them as a `srcset` and keep `url` for the original. - AVIF (`:avif`, off by default; `:avif_quality` 55, `:avif_effort` 3): the sizes go out as AVIF to clients whose `Accept` has `image/avif`, with `Vary: Accept`; about 40% smaller than JPEG q70 at the same SSIM, ~0.7 s to encode a 1600 px image on a small VPS (JPEG: 0.14 s). Needs a libvips with libheif and an AV1 encoder; without it, or when an encode fails, the sizes stay JPEG/PNG. Thumbnails stay JPEG/PNG. The Docker image adds `vips-heif` (build and runtime stage: Vix makes its functions from what libvips offers at compile time). - Config description, cheatsheet, API schema and changelog updated.
The preview proxy takes a size param: one of :image_sizes (the long
side, default 960, 1600, 2560), compared as written, so that other
spellings cannot add resizes or cache entries. Anything else redirects
to the thumbnail.
MastodonAPI: list image preview sizes on attachments
All checks were successful
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.15 Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline was successful
227eeb631b
pleroma.image_sizes: the previews smaller than the image, with their
approximate dimensions when known, for clients to use as a srcset.
MediaProxy: image sizes as AVIF for clients that accept it
All checks were successful
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.15 Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline was successful
3046dcad6d
:avif (off by default), :avif_quality 55, :avif_effort 3: about 40%
smaller than JPEG at the same quality. Only the sizes, only when libvips
can encode AVIF; the size responses vary on Accept. A failed encode
falls back to JPEG/PNG. The Docker image adds vips-heif.
lambadalambda changed title from Media preview proxy: image previews in configured sizes to Media preview proxy: image previews in configured sizes, optionally AVIF 2026-10-01 07:32:07 +00:00
Owner

AVIF has a lot of support now, worth using 👍

AVIF has a lot of support now, worth using 👍
All checks were successful
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.15 Pipeline was successful
ci/woodpecker/pr/unit-testing-elixir-1.19 Pipeline was successful
This pull request has changes conflicting with the target branch.
  • Dockerfile
  • lib/pleroma/web/media_proxy/media_proxy_controller.ex
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u feature/media-preview-sizes:lambadalambda-feature/media-preview-sizes
git switch lambadalambda-feature/media-preview-sizes

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch develop
git merge --no-ff lambadalambda-feature/media-preview-sizes
git switch lambadalambda-feature/media-preview-sizes
git rebase develop
git switch develop
git merge --ff-only lambadalambda-feature/media-preview-sizes
git switch lambadalambda-feature/media-preview-sizes
git rebase develop
git switch develop
git merge --no-ff lambadalambda-feature/media-preview-sizes
git switch develop
git merge --squash lambadalambda-feature/media-preview-sizes
git switch develop
git merge --ff-only lambadalambda-feature/media-preview-sizes
git switch develop
git merge lambadalambda-feature/media-preview-sizes
git push origin develop
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
pleroma/pleroma!7997
No description provided.