Skip to content

fix: resolve font NameError, JPEG/webp mismatch, and duplicate Tower …of Hanoi entry- Load fonts once at top of generate_banner() to fix NameError in matrix branch- Bundle DejaVu Sans Bold font for consistent cross-platform rendering- Warn via RuntimeWarning if no font is found instead of failing silently- Save banners as true WebP instead of JPEG bytes in a .webp file- Remove duplicate Tower of Hanoi entry that silently overwrote its own output#1272

Merged
steam-bell-92 merged 1 commit into
steam-bell-92:mainfrom
Tech4Aditya:fix/font-fallback-warning
Jun 19, 2026

Conversation

@Tech4Aditya

Copy link
Copy Markdown
Contributor

📝 Description

Fixes three bugs and bundles a missing asset in web-app/generate_banners.py:

1. NameError crash on the "matrix" banner branch
font_title was referenced inside the matrix branch of the if-elif chain but only defined ~80 lines later, after the chain. Any banner with "matrix" in its name (e.g. Matrix Calculator) crashed with NameError: name 'font_title' is not defined. Fixed by extracting font loading into a load_fonts() helper called once at the top of generate_banner(), before any drawing logic runs.

2. Silent font fallback made banner text unreadable on non-Windows machines
The original fallback chain only checked segoeui.ttf and arial.ttf — both Windows-only fonts that don't exist on Linux/macOS/CI. When neither was found, it silently fell back to ImageFont.load_default() (a ~10px bitmap font), with no warning logged. Every banner generated outside Windows had broken text and no one would know. Fixed by:

  • Bundling assets/fonts/DejaVuSans-Bold.ttf (Bitstream Vera license, safe to vendor) so font loading is OS-independent and requires no system font.
  • Checking the bundled font first, then Windows fonts, then a common Linux system path.
  • Emitting a RuntimeWarning only if every option fails, so the failure is now visible instead of silent.

3. Output saved as JPEG bytes inside a .webp file
final_img.save(filename, "JPEG", quality=90) wrote JPEG-encoded data to paths ending in .webp. Tools/browsers reading by extension would attempt WebP decoding and fail or show corrupted output. Fixed by saving with "WEBP" format and method=6 (libwebp's best compression preset, fine since this only runs at build time).

4. Duplicate "Tower of Hanoi" entry silently overwrote its own output
The projects list had two entries (math and utilities) pointing to the same filename tower-of-hanoi.webp. The second call silently overwrote the first, so the utilities-styled banner never made it to disk. Removed the duplicate with an inline comment explaining why.

Note: this file already depends on Pillow (PIL) before my changes — I didn't introduce a new third-party dependency. Flagging in case the "standard library only" guideline needs a separate conversation about the existing PIL usage.

🔗 Linked Issue

Closes #1183


📋 Contribution Checklist

  • My code strictly adheres to the project guidelines (Standard library only, procedural code, clean spacing).
  • I have verified that my files are placed in the correct directory.
  • I have tested my changes thoroughly on my local machine.
  • I have included interactive emojis and clean console/UI outputs.
  • GSSoC 2026: I have been formally assigned to this issue and noted it above.

…of Hanoi entry- Load fonts once at top of generate_banner() to fix NameError in matrix branch- Bundle DejaVu Sans Bold font for consistent cross-platform rendering- Warn via RuntimeWarning if no font is found instead of failing silently- Save banners as true WebP instead of JPEG bytes in a .webp file- Remove duplicate Tower of Hanoi entry that silently overwrote its own output
@vercel

vercel Bot commented Jun 19, 2026

Copy link
Copy Markdown

@Tech4Aditya is attempting to deploy a commit to the Anuj's projects Team on Vercel.

A member of the Team first needs to authorize it.

@steam-bell-92 steam-bell-92 merged commit f5cfbb6 into steam-bell-92:main Jun 19, 2026
9 of 11 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🎉 Thank you for your contribution!

Your Pull Request has been merged successfully.

We appreciate the time and effort you put into improving this project. Contributions like yours help the repository grow and stay useful for everyone.

If you'd like to contribute again, please check the open issues and make sure you are assigned before opening another Pull Request.

Thanks again for your support! 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 [Bug]: warn on font fallback and document required system fonts for headless environments

2 participants