Files
Paperwall/screens/picture.py
T
Honey 132e133b1d All screens: drop gray text, matching the Journey fix
The epd4in0e panel's palette has no gray at all (just black/white/
yellow/red/blue/green -- see epd4in0e.py's putpalette), so any gray
RGB fill gets Floyd-Steinberg dithered into a black/white checkerboard
across the whole glyph body. At the small font sizes most of these
screens use (Navidrome's artist/album/genre/source lines, Departures'
direction/platform columns, Weather's description/forecast labels,
Clock's date line, the placeholder messages), that reads as blurry,
half-rendered text -- same root cause already fixed in Journey.

Switched every gray fill/outline to solid black across navidrome.py,
weather.py, departures.py, clock.py, and picture.py. Left the
intentionally-faint row-divider hairlines (228,228,228) alone --
those are meant to almost disappear, not readable text. Removed
departures.py's now-unused MUTED constant.
2026-07-23 11:56:24 +02:00

89 lines
3.0 KiB
Python

"""Shows a picture -- either uploaded through the web UI or fetched from a
URL on a timer. Same contrast-boost/grayscale treatment as the Navidrome
cover art, since the same e-ink legibility concerns apply.
"""
import logging
from io import BytesIO
from pathlib import Path
import requests
from PIL import Image, ImageDraw, ImageEnhance
from screens.base import Screen
from screens.render_utils import fit_contain, fit_cover, load_font, text_width
logger = logging.getLogger(__name__)
HTTP_TIMEOUT = 15
UPLOAD_DIR = Path(__file__).resolve().parent.parent / "web" / "static" / "uploads"
class PictureScreen(Screen):
id = "picture"
display_name = "Picture"
poll_interval = 1800 # 30 minutes -- only matters for url mode
def default_settings(self) -> dict:
return {
"mode": "url", # "url" or "upload"
"image_url": "",
"uploaded_filename": "",
"fit": "cover", # "cover" or "contain"
"boost_contrast": True,
"grayscale": False,
}
def check(self, settings: dict):
mode = settings.get("mode", "url")
if mode == "upload":
filename = settings.get("uploaded_filename")
if not filename:
return None
path = UPLOAD_DIR / filename
if not path.exists():
logger.warning("Uploaded picture %s is missing", path)
return None
try:
return Image.open(path).convert("RGB")
except OSError as exc:
logger.warning("Could not open uploaded picture %s: %s", path, exc)
return None
url = (settings.get("image_url") or "").strip()
if not url:
return None
try:
response = requests.get(url, timeout=HTTP_TIMEOUT)
response.raise_for_status()
return Image.open(BytesIO(response.content)).convert("RGB")
except (requests.exceptions.RequestException, OSError) as exc:
logger.warning("Could not load picture from %s: %s", url, exc)
return None
def render(self, state, settings: dict, resolution: tuple[int, int]) -> Image.Image:
width, height = resolution
if state is None:
image = Image.new("RGB", (width, height), "white")
draw = ImageDraw.Draw(image)
font = load_font(size=int(min(width, height) * 0.06))
msg = "Kein Bild konfiguriert"
mw = text_width(draw, msg, font)
draw.text(((width - mw) / 2, height / 2), msg, font=font, fill="black")
return image
if settings.get("fit", "cover") == "contain":
image = fit_contain(state, width, height)
else:
image = fit_cover(state, width, height)
if settings.get("boost_contrast", True):
image = ImageEnhance.Contrast(image).enhance(1.35)
image = ImageEnhance.Brightness(image).enhance(1.05)
if settings.get("grayscale", False):
image = image.convert("L").convert("RGB")
return image