Skip to content

Bug: sometimes white text is unreadable #12

Open

Description

@asterizk

Sometimes white text is completely unreadable when overlaid onto an image. Detect when this is likely and change text color to black. See also #5

example from 2026-07-19:
Image

Activity

  1. asterizk commented on Sep 28, 2026

    @asterizk
    OwnerAuthor

    Another, more extreme example from 2026-09-28 ("Cosmic Latte: The Average Color of the Universe"). The APOD image is almost a solid #FFF8E7, so the white title and body text are nearly invisible.

    Image

    Cause: in starhop.py, the title is drawn with a hard-coded fill=(255, 255, 255). The body multiline_text call passes no fill, so it uses Pillow's default ink, which is white in RGB mode. There's no outline, shadow or backing panel, and nothing checks how bright the image is behind the text.

    Possible fixes (can be combined):

    1. Choose the text color from brightness. Crop the area under the title and body, measure its average brightness (e.g. ImageStat.Stat(region.convert("L")).mean), and draw in black if the background is bright, white if it's dark.
    2. Outline the text. Pass stroke_width and a contrasting stroke_fill to text() and multiline_text(), so the text stays readable on any background, including busy ones like White frame around original image yields only partially readable caption #6.
    3. Put a see-through panel behind the caption. Draw a semi-transparent dark rectangle behind the text block.

    Also, pass fill explicitly to the body text, not just the title. That keeps the two consistent and may be related to #5.

    Test case: 2026-09-28 works well for a regression test, because the image is nearly one uniform light color.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions