Implement CSS-based QR code coloring with transparent backgrounds#18
Implement CSS-based QR code coloring with transparent backgrounds#18
Conversation
- Updated generate_qr_svg.py to generate QR codes with transparent backgrounds (light=None) - Changed from fill-based to stroke-based currentColor for QR modules - Added 'qrcode-box' class to generated SVG elements - Updated HTML CSS to set color on .qrcode-box which flows to SVG via currentColor - Updated reference test files for new SVG structure - Cleared TODO.md as all items are completed - All tests passing (38/38) - Linter clean (flake8) Co-authored-by: zaxlofful <33877007+zaxlofful@users.noreply.github.com>
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ❌ Deployment failed View logs |
simplewish | 61de5a0 | Jan 02 2026, 06:05 AM |
There was a problem hiding this comment.
Pull request overview
This PR implements CSS-based QR code coloring to enable instant color changes without regenerating SVG files. The implementation generates QR codes with transparent backgrounds and uses CSS currentColor to control the foreground color, reducing data size and improving flexibility.
Key Changes
- Modified QR generation to create transparent backgrounds using
light=Noneand replace hardcoded stroke colors withstroke="currentColor" - Added
qrcode-boxclass to generated SVG elements and set thecolorCSS property on.qrcode-boxcontainers to control QR appearance - Updated test reference files to reflect the new SVG structure without background fills
Reviewed changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
scripts/generate_qr_svg.py |
Modified to generate transparent QR codes with currentColor strokes and added qrcode-box class for CSS targeting |
index.html |
Added color:#0b6623 to .qrcode-box CSS rule and updated embedded QR SVG to use currentColor |
elsa.html |
Added color:#1565C0 to .qrcode-box CSS rule and updated embedded QR SVG to use currentColor |
tests/reference_qr.svg |
Updated reference to match new transparent QR structure with currentColor strokes |
tests/reference_elsa_qr.svg |
Updated reference to match new transparent QR structure with currentColor strokes |
TODO.md |
Removed completed TODO items about CSS-based coloring implementation |
| dark=foreground_color, light=background_color, border=border | ||
| dark=foreground_color, light=None, border=border | ||
| ) | ||
|
|
There was a problem hiding this comment.
The function now always uses light=None to create transparent backgrounds, which means the background_color parameter in the function signature (line 325) is no longer used. However, the parameter still exists and is being passed by callers (e.g., line 775 in main()).
This creates an inconsistent API where:
- The CLI still accepts
--background-color - Meta tags still read
qr-background-color - These values are passed to the function but silently ignored
Consider either removing the unused parameter from the function signature and updating all callers, or documenting that this parameter is now ignored in favor of CSS-controlled transparency.
| # Propagate the requested background color as metadata on the root SVG. | |
| # This keeps the QR visually transparent while preserving the value | |
| # provided via CLI/meta for downstream consumers (CSS/JS or tooling). | |
| if background_color is not None: | |
| svg = re.sub( | |
| r'(<svg\b[^>]*?)>', | |
| r'\1 data-qr-background-color="' + background_color + '">', | |
| svg, | |
| count=1, | |
| ) |
AI Review Edits Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Implemented CSS-controlled QR code colors using
currentColorand transparent backgrounds, eliminating the need to regenerate SVGs when changing colors.Changes
QR Generation (
scripts/generate_qr_svg.py)light=Noneparameterstroke="currentColor"qrcode-boxclass to SVG elements for CSS targetingHTML Templates
colorproperty on.qrcode-boxto control QR foreground colorTest References
reference_qr.svgandreference_elsa_qr.svgfor new SVG structureUsage
Change QR color via CSS without regeneration:
The SVG's
stroke="currentColor"inherits from parent element'scolorproperty.Visual Results
Green QR (default)

Blue QR (Elsa's theme)

Original prompt
💡 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.