Image quality gate: reject too-small images (no more blurry thumbnails)
Some cards showed blurry photos — feed RSS thumbnails (~90×90, e.g. Phys.org's /tmb/ path) that load fine but upscale to mush in the banner. Add a header-based dimension parser (PNG/GIF/JPEG/WebP, stdlib only) and fold a minimum-size gate (450×250) into the image validation, alongside the existing load check. Images we can't measure (SVG/AVIF) still pass on content-type. A re-prune clears the small ones already stored so those cards fall back to the clean placeholder. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -68,3 +68,13 @@ def test_backfill_only_targets_summarized_accepted_imageless(tmp_path):
|
||||
n = enrich.enrich_summarized_images(c, fetch=lambda url: "http://og.jpg", limit=50)
|
||||
assert n == 1
|
||||
assert c.execute("SELECT image_url FROM articles WHERE id=2").fetchone()[0] is None
|
||||
|
||||
|
||||
def test_image_dimensions_parses_headers():
|
||||
import struct
|
||||
from goodnews import enrich
|
||||
png = b"\x89PNG\r\n\x1a\n" + b"\x00\x00\x00\x0d" + b"IHDR" + struct.pack(">II", 1200, 630)
|
||||
assert enrich._image_dimensions(png) == (1200, 630)
|
||||
gif = b"GIF89a" + struct.pack("<HH", 90, 90)
|
||||
assert enrich._image_dimensions(gif) == (90, 90)
|
||||
assert enrich._image_dimensions(b"not an image at all") is None
|
||||
|
||||
Reference in New Issue
Block a user