Skip to content

Ask Wikimedia for a rasterized PNG instead of raw SVG#22

Merged
fleveque merged 1 commit into
mainfrom
fix/wikidata-request-prerasterized-png
May 16, 2026
Merged

Ask Wikimedia for a rasterized PNG instead of raw SVG#22
fleveque merged 1 commit into
mainfrom
fix/wikidata-request-prerasterized-png

Conversation

@fleveque

Copy link
Copy Markdown
Owner

What just happened

After yesterday's librsvg install (#21), the very next REP.MC request still hung at processing for ~30s before kamal-proxy 504'd:

```
22:59:16 cache miss for REP.MC
22:59:17 found logo via Wikidata, source=wikidata:Q174747
[504 — no further logs]
```

`kamal app exec --reuse "vips --vips-config | grep rsvg"` returned "no rsvg in vips config" — the Alpine `vips` package was compiled WITHOUT rsvg support. Installing librsvg as a runtime lib does nothing; libvips can't load it.

Fix

Wikimedia rasterizes server-side via `Special:FilePath/?width=N`. Append `?width=512` to the URL and:

  • For SVG sources, Wikimedia redirects to a real PNG thumbnail (verified: 301 → `upload.wikimedia.org/.../960px-Repsol_logo.svg.png` → genuine PNG bytes, 960×240).
  • For raster sources, the query param is ignored and we get the original file.

Either way, our libvips downstream only sees PNG, which it handles fine.

512 was chosen so the largest output size (xl=256px) downsamples cleanly with quality headroom.

Test plan

  • Sandbox curl confirmed Special:FilePath?width= returns a PNG redirect.
  • `go test ./internal/provider/` — new assertion that the OriginalURL contains `width=`.
  • After deploy, hit REP.MC and DGE.L; expect a quick `found logo via Wikidata` followed by the request completing (no 504). `file` on the response should say "PNG image".

🤖 Generated with Claude Code

After yesterday's librsvg install (#21), the next REP.MC request still
hung at processing — turns out the Alpine `vips` package is compiled
WITHOUT rsvg support (verified via `vips --vips-config`), so installing
librsvg as a runtime lib does nothing. libvips can't load it.

Fortunately Wikimedia exposes server-side rasterization via the
`Special:FilePath/<file>?width=N` endpoint: when the source is SVG it
redirects to a thumbnail-server PNG; when it's already a raster the
query param is ignored. Either way, our downstream libvips pipeline
only sees PNG bytes — which it handles fine without librsvg.

Sandbox-verified: hit Special:FilePath/Repsol_logo.svg?width=512 →
HTTP 301 → upload.wikimedia.org/...//960px-Repsol_logo.svg.png → real
PNG (960×240, 8-bit RGBA). 512 chosen so the largest output size
(xl=256px) downsamples cleanly with headroom.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@fleveque fleveque merged commit d3ca610 into main May 16, 2026
2 checks passed
@fleveque fleveque deleted the fix/wikidata-request-prerasterized-png branch May 16, 2026 23:04
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