Skip to content

Optimize new player avatars without changing dimensions or animation - #2763

Merged
MathiasGruber merged 1 commit into
mainfrom
codex/automatic-avatar-optimization
Dec 3, 2026
Merged

MathiasGruber merged 1 commit into
mainfrom
codex/automatic-avatar-optimization

Conversation

@MathiasGruber

@MathiasGruber MathiasGruber commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

New avatar uploads and generated player portraits publish a smaller WebP copy when it preserves the source dimensions, animation frames, timing and loop settings. Browser and API uploads share the same step after moderation; the resulting URL is used consistently for history, thumbnails and confirmed profile patches.

Original uploads remain available. Existing smaller files, APNG, oriented images, unsupported conversions and failed downloads or uploads retain the original URL. The optional conversion has byte, decoded-pixel and processing limits. It does not impose a fixed file-size target or alter existing player avatars in bulk.

Validation: 158 tests passed across six affected suites, including real SQL upload/history/cache and generation payment guards, animated GIF/WebP checks, alpha preservation and fallback behavior. TypeScript and pinned Biome checks passed. Tutorial routes, progression and guidance are unaffected. No preview or production deployment was triggered.

License

By making this pull request, I confirm that I have the right to waive copyright and related rights to my contribution, and agree that all copyright and related rights in my contributions are waived, and I acknowledge that the Studie-Tech ApS organization has the copyright to use and modify my contribution for perpetuity.

Summary by CodeRabbit

  • New Features
    • Avatar uploads now use an optimized WebP image when conversion succeeds and the result is smaller, helping reduce image size while preserving the original when optimization isn’t suitable.
    • Optimized images are used for profile avatars, thumbnails, and avatar history.
  • Tests
    • Added coverage for image conversion, preservation of animation and orientation, and fallback behavior when optimization fails.

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds optimizeAvatarImage to create smaller WebP copies of eligible avatar images. Avatar upload and generation flows use its returned URL for avatar generation, thumbnails, and avatar records.

Changes

Avatar image optimization

Layer / File(s) Summary
Image optimization and validation
app/src/server/utils/avatarImages.ts, app/tests/server/utils/avatarImages.test.ts
optimizeAvatarImage checks source URLs, applies download and decode limits, and uploads a WebP only when it is smaller and metadata checks pass. Tests cover conversion, unchanged originals, and failure cases.
Avatar upload and generation wiring
app/src/server/api/routers/avatar.ts, app/src/server/utils/imageUploads.ts, app/tests/app/api/uploadthing/avatarCache.test.ts, app/tests/server/api/routers/avatar.userCache.test.ts, app/tests/server/api/routers/upload.test.ts
Avatar flows use the selected URL for generation, thumbnails, returned file URLs, and avatar records. Tests verify URL selection and confirm that moderation still uses the stored UFS URL.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant UploadCallback
  participant optimizeAvatarImage
  participant UploadThing
  participant AvatarGeneration
  participant ThumbnailCreation
  UploadCallback->>optimizeAvatarImage: pass uploaded avatar file
  optimizeAvatarImage->>UploadThing: fetch source image
  UploadThing-->>optimizeAvatarImage: return source image bytes
  optimizeAvatarImage->>UploadThing: upload smaller WebP when validation passes
  UploadThing-->>optimizeAvatarImage: return WebP served URL
  optimizeAvatarImage-->>UploadCallback: return optimized URL or original URL
  UploadCallback->>AvatarGeneration: pass selected avatar URL
  UploadCallback->>ThumbnailCreation: pass selected avatar URL
Loading
Merge Risk: Minimal · up to dd070

New avatar uploads and generated portraits now get a smaller WebP copy when conversion preserves dimensions and animation. In every other case, or if anything fails, the original image is kept. No merge-blocking issue was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "Optimize new player avatars without changing dimensions or animation" matches the main change: new avatar uploads and generated player portraits get a smaller WebP copy that keeps the sourc…
Description check Passed The description covers what was implemented, why the optimization preserves dimensions and animation, and which cases keep the original URL. It also reports validation results and states that no previ…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Optimize new player avatars without changing dimensions or animation" matches the main change: new avatar uploads and generated player portraits get a smaller WebP copy that keeps the source dimensions, animation frames, timing, and loop settings. The changeset adds optimizeAvatarImage in avatarImages.ts, routes avatar uploads through it in imageUploads.ts and avatar.ts, and adds tests for conversion, animation retention, and fallbacks. The title is specific and concise and does not describe anything absent from the changeset.

Full details: Description check

Explanation

The description covers what was implemented, why the optimization preserves dimensions and animation, and which cases keep the original URL. It also reports validation results and states that no preview or production deployment was triggered. It does not fill the template's breaking-change prompt, and it does not follow the template's Vercel preview section, which is a standard note rather than an author-filled field. The License section is present and unchanged. Most required content is present.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit packed a portrait tight,
And checked each frame and pixel right.
A smaller WebP joined the queue,
Or else the source came safely through.
The avatar and thumbnail share,
The chosen link, prepared with care.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: c1c72b2b-5804-4708-868d-9f09eaacf844
Commits

Reviewing files that changed from the base of the PR and between 425e17a and dd07050.

Files selected for processing: 7

  • app/src/server/api/routers/avatar.ts
  • app/src/server/utils/avatarImages.ts
  • app/src/server/utils/imageUploads.ts
  • app/tests/app/api/uploadthing/avatarCache.test.ts
  • app/tests/server/api/routers/avatar.userCache.test.ts
  • app/tests/server/api/routers/upload.test.ts
  • app/tests/server/utils/avatarImages.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 5 included reviews per hour; 1 remain after this review.

@MathiasGruber
MathiasGruber merged commit 8685f83 into main Dec 3, 2026
13 checks passed
@MathiasGruber
MathiasGruber deleted the codex/automatic-avatar-optimization branch December 3, 2026 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant