Render via memegen API; Pillow fallback for custom images#21
Merged
brianckeegan merged 1 commit intomainfrom Apr 28, 2026
Merged
Render via memegen API; Pillow fallback for custom images#21brianckeegan merged 1 commit intomainfrom
brianckeegan merged 1 commit intomainfrom
Conversation
…-line styling Rewires the rendering pipeline around three backends (auto / memegen / pillow / matplotlib). Memes from the memegen catalogue are now composed server-side via /images/<id>/<line>.../<line>.<ext>?... URLs and `imshow`n; custom local images and any feature memegen can't express (per-line fontsize, custom outlines, **text_kwargs, per-line overrides) route to a new client-side Pillow renderer. The legacy matplotlib `Axes.text` + patheffects path is preserved as `backend="matplotlib"`. References jacebrowning/memegen#993 for the URL grammar and adds a docs/url_construction.rst guide adapted for memeplotlib users. - New `_url.py` (build_memegen_url, OverlaySpec, MEMEGEN_FONT_ALIASES) and `_pillow.py` (TTF resolution, multiline shrink-to-fit, stroke-aware drawing). - `meme()` uses sentinel detection to know which knobs the caller passed so `auto` can route correctly. New params: backend, extension, width, height, layout, background, overlays, template_style. - `Meme.line(index, text, *, fontsize, color, font, position)` for per-line overrides; `Meme.with_backend(...)` chainable setter. - `Template` carries lines_count / overlays_count / styles / is_memegen. - `Template.get_image()` now respects config["cache_enabled"] (latent bug). - CLI gains --backend / --ext / --width / --height / --layout / --background / --template-style. - MCP `meme` tool accepts the new knobs. - Version bumped to 0.5.0 across pyproject.toml, __init__.py, and both conda recipes. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
auto/memegen/pillow/matplotlib). By defaultmeme()now constructs a memegen rendering URL (/images/<id>/<line>/.../<line>.<ext>?style=...&font=...), fetches the composed image, andimshows it.fontsize, custom outlines,**text_kwargs, per-line overrides) route to a new client-side Pillow renderer. LegacyAxes.text+ path-effects rendering is preserved asbackend="matplotlib".Meme.line(index, text, *, fontsize=, color=, font=, position=)for per-line overrides andMeme.with_backend(...)chainable setter.meme()knobs:backend,extension,width,height,layout,background,overlays,template_style. CLI and MCP gain matching arguments.Templatenow carrieslines_count/overlays_count/styles/is_memegen.docs/url_construction.rst, adapted from jacebrowning/memegen#993.Why
The memegen API can compose entire memes server-side, but memeplotlib was only using it to fetch blank backgrounds and re-implementing text composition client-side with matplotlib. That left memegen features (template styles, custom fonts/colours, dimensions, layouts, custom backgrounds, overlay slots) unused. Routing the default path through the API gives users canonical memegen output for free; the Pillow fallback covers the cases the API can't reach (custom local images, explicit fontsize, custom outlines).
Reviewer notes
tests/conftest.pypins legacy tests tobackend="matplotlib"; new tests for the memegen and pillow paths opt in via@pytest.mark.uses_default_backend. Users who want exact v0.4 visuals can passbackend="matplotlib"or setconfig["backend"] = "matplotlib".fontsize. Underauto, passing those forces the Pillow backend automatically; underbackend="memegen"they are silently ignored. This is documented in the changelog and CLAUDE.md.meme():outline_color,outline_width,fontsizedefault to a private_UNSETsentinel so the dispatcher can tell "user passed it" from "user accepted the default"._UNSETis treated asNoneby every downstream consumer.Template.get_image()now respectsconfig["cache_enabled"]. This was a latent bug surfaced while writing tests — under the old behaviour, disabling caching at the config level didn't actually disable the cache instance, so tests could read stale data from the user's real cache directory.memegen_rendered_pattern("buzz")helper intests/conftest.pyfor regex matching withresponses.Test plan
ruff check .black --check .mypy --strict src/memeplotlibpytest --cov --mpl— 222 passed, 88% coverage (≥ 85% gate)sphinx-build -W docs docs/_buildpytest -m integration)🤖 Generated with Claude Code