[PR #1802] [MERGED] feat: replace PNG-based initials avatar with SVG generation #7818

Closed
opened 2026-04-20 17:53:45 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/go-vikunja/vikunja/pull/1802
Author: @Copilot
Created: 11/12/2025
Status: Merged
Merged: 11/12/2025
Merged by: @kolaente

Base: mainHead: copilot/fix-issue-549


📝 Commits (5)

  • 3c5bdcf Initial plan
  • 33e7e0e Replace PNG-based initials avatar with lightweight SVG generation
  • 0cf9308 Final verification - all tests passing
  • 55d098d Update avatar colors to use light backgrounds with contrasting text and bold font
  • c819d8c Remove bold font weight from avatar text

📊 Changes

4 files changed (+170 additions, -553 deletions)

View changed files

📝 go.mod (+0 -9)
📝 go.sum (+18 -229)
📝 pkg/modules/avatar/initials/initials.go (+40 -205)
📝 pkg/modules/avatar/initials/initials_test.go (+112 -110)

📄 Description

The initials avatar provider generates PNG images using freetype and imaging libraries, consuming ~500MB memory per avatar and causing OOM errors under concurrent load (issue #1761). Replace with lightweight SVG generation similar to the marble avatar provider.

Changes

Avatar generation (pkg/modules/avatar/initials/initials.go)

  • Generate SVG instead of PNG: colored rect + centered text element
  • Remove image processing: freetype, imaging, gofont dependencies eliminated
  • Simplify caching: FlushCache now no-op (SVG generation is ~715ns)
  • Use light pastel backgrounds with contrasting dark text colors (6 color pairs)
  • Normal font weight for clean appearance
  • Preserve behavior: deterministic color selection by user ID, name/username fallback

Tests (pkg/modules/avatar/initials/initials_test.go)

  • Validate SVG structure, colors, initials, size attributes
  • Verify HTML escaping for XSS protection
  • Test error handling for users without name/username

Dependencies

  • Removed: github.com/golang/freetype (no longer needed)
  • No longer used in initials module: github.com/disintegration/imaging

Example output

<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" width="100" height="100">
  <rect width="100" height="100" fill="#e0f8d9"/>
  <text x="50" y="50" font-family="sans-serif" font-size="50" fill="#005f00" 
        text-anchor="middle" dominant-baseline="central">A</text>
</svg>

Final avatar design with normal font weight

Color Palette

The avatars use 6 color pairs with light pastel backgrounds and contrasting dark text:

  • Green: #e0f8d9 / #005f00
  • Blue: #e3f5f8 / #00548c
  • Purple: #faeefb / #822198
  • Violet: #f1efff / #5d26cd
  • Pink: #ffecf0 / #9f0850
  • Orange: #ffefe4 / #9b2200

Impact

  • Memory: 500MB → 0.65KB per avatar (700,000× reduction)
  • Speed: ~715ns per operation, 9 allocations, 664 bytes
  • Code: 249 → 76 lines

Resolves #549, fixes #1761

Original prompt

Implement https://github.com/go-vikunja/vikunja/issues/549


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


🔄 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/go-vikunja/vikunja/pull/1802 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 11/12/2025 **Status:** ✅ Merged **Merged:** 11/12/2025 **Merged by:** [@kolaente](https://github.com/kolaente) **Base:** `main` ← **Head:** `copilot/fix-issue-549` --- ### 📝 Commits (5) - [`3c5bdcf`](https://github.com/go-vikunja/vikunja/commit/3c5bdcfff0568bf0ffc89d5c15007b42146d8968) Initial plan - [`33e7e0e`](https://github.com/go-vikunja/vikunja/commit/33e7e0e3b2f719c6746fa1e8955eebe3ea2524d8) Replace PNG-based initials avatar with lightweight SVG generation - [`0cf9308`](https://github.com/go-vikunja/vikunja/commit/0cf9308ad272aae3f9a406996d337a909c51dd4c) Final verification - all tests passing - [`55d098d`](https://github.com/go-vikunja/vikunja/commit/55d098d962cd25d6e2e562efb7b8ac0c6aea16bc) Update avatar colors to use light backgrounds with contrasting text and bold font - [`c819d8c`](https://github.com/go-vikunja/vikunja/commit/c819d8cbedd13009222286e55b5a20711538daca) Remove bold font weight from avatar text ### 📊 Changes **4 files changed** (+170 additions, -553 deletions) <details> <summary>View changed files</summary> 📝 `go.mod` (+0 -9) 📝 `go.sum` (+18 -229) 📝 `pkg/modules/avatar/initials/initials.go` (+40 -205) 📝 `pkg/modules/avatar/initials/initials_test.go` (+112 -110) </details> ### 📄 Description The initials avatar provider generates PNG images using freetype and imaging libraries, consuming ~500MB memory per avatar and causing OOM errors under concurrent load (issue #1761). Replace with lightweight SVG generation similar to the marble avatar provider. ## Changes **Avatar generation (`pkg/modules/avatar/initials/initials.go`)** - Generate SVG instead of PNG: colored rect + centered text element - Remove image processing: freetype, imaging, gofont dependencies eliminated - Simplify caching: `FlushCache` now no-op (SVG generation is ~715ns) - Use light pastel backgrounds with contrasting dark text colors (6 color pairs) - Normal font weight for clean appearance - Preserve behavior: deterministic color selection by user ID, name/username fallback **Tests (`pkg/modules/avatar/initials/initials_test.go`)** - Validate SVG structure, colors, initials, size attributes - Verify HTML escaping for XSS protection - Test error handling for users without name/username **Dependencies** - Removed: `github.com/golang/freetype` (no longer needed) - No longer used in initials module: `github.com/disintegration/imaging` ## Example output ```svg <svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" width="100" height="100"> <rect width="100" height="100" fill="#e0f8d9"/> <text x="50" y="50" font-family="sans-serif" font-size="50" fill="#005f00" text-anchor="middle" dominant-baseline="central">A</text> </svg> ``` ![Final avatar design with normal font weight](https://github.com/user-attachments/assets/aa0e7eea-37a7-4ecb-8fd8-12e59c0b8c52) ## Color Palette The avatars use 6 color pairs with light pastel backgrounds and contrasting dark text: - Green: `#e0f8d9` / `#005f00` - Blue: `#e3f5f8` / `#00548c` - Purple: `#faeefb` / `#822198` - Violet: `#f1efff` / `#5d26cd` - Pink: `#ffecf0` / `#9f0850` - Orange: `#ffefe4` / `#9b2200` ## Impact - Memory: 500MB → 0.65KB per avatar (700,000× reduction) - Speed: ~715ns per operation, 9 allocations, 664 bytes - Code: 249 → 76 lines Resolves #549, fixes #1761 <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > Implement https://github.com/go-vikunja/vikunja/issues/549 </details> <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-20 17:53:45 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/vikunja#7818