Street-poster cover, graffiti type and ASCII art
Mirror to Gitea / mirror (push) Skipped

Turn the home cover into a two-tone street poster: stacked-letter title
band, manga panels, graffiti and drip lettering, speech bubbles and fold
creases. Add a live ASCII canvas, Tag and PosterBand components, graffiti
fonts, and jsr / popart / ascii presets to tools/fx.py.
This commit is contained in:
Johan Sandoval committed 2026-10-08 17:17:09 +00:00
1 parent a8d193cde0
commit 48dcaaac25
20 files changed
+674 -224

No files matched your search

+135 -1
View File
@@ -164,7 +164,133 @@ def vintage(img):
return dust(vignette(grain(out, 16), 0.6), specks=700, scratches=10)
LOOKS = {'toon': toon, 'pixel': pixel, 'xerox': xerox, 'riso': riso, 'vintage': vintage}
# ---------- poster / comic / terminal looks ----------
def _halftone_mask(density, cell=7, angle=45):
"""Return a boolean ink mask: round dots whose size follows density (0..1)."""
h, w = density.shape
y, x = np.mgrid[0:h, 0:w].astype(np.float32)
a = np.deg2rad(angle)
u = x * np.cos(a) + y * np.sin(a)
v = -x * np.sin(a) + y * np.cos(a)
fu = (u / cell) % 1 - 0.5
fv = (v / cell) % 1 - 0.5
dist = np.sqrt(fu * fu + fv * fv)
radius = np.sqrt(np.clip(density, 0, 1)) * 0.62
return dist < radius
def _ink_edges(img, thresh=22, thick=3):
g = img.convert('L').filter(ImageFilter.GaussianBlur(1.2))
e = g.filter(ImageFilter.FIND_EDGES).point(lambda v: 255 if v > thresh else 0)
if thick > 1:
e = e.filter(ImageFilter.MaxFilter(thick | 1))
return np.asarray(e) > 0
def creases(img, folds=((0.5, 'v'), (0.33, 'h'), (0.66, 'h')), strength=0.18):
"""Paper fold lines: a bright ridge next to a dark valley."""
a = np.asarray(img, dtype=np.float32).copy()
h, w = a.shape[:2]
for pos, d in folds:
if d == 'v':
c = int(w * pos)
for off, k in ((-2, 1 + strength), (-1, 1 + strength * 0.6), (1, 1 - strength), (2, 1 - strength * 0.6)):
if 0 <= c + off < w:
a[:, c + off] *= k
else:
c = int(h * pos)
for off, k in ((-2, 1 + strength), (-1, 1 + strength * 0.6), (1, 1 - strength), (2, 1 - strength * 0.6)):
if 0 <= c + off < h:
a[c + off, :] *= k
return Image.fromarray(np.clip(a, 0, 255).astype(np.uint8))
def jsr(img, ink=(46, 92, 44), paper=(226, 233, 150), cell=6, outline=True):
"""Two-tone street poster: one ink on coloured stock, halftone mid-tones,
solid shadows, ink outlines, fold creases, speckle and wear."""
g = ImageOps.autocontrast(img.convert('L'), cutoff=2)
g = ImageEnhance.Contrast(g).enhance(1.25)
g = ImageEnhance.Brightness(g).enhance(1.12)
d = 1 - np.asarray(g, dtype=np.float32) / 255
ink_mask = _halftone_mask(np.clip((d - 0.28) / 0.55, 0, 1) ** 1.2, cell=cell)
ink_mask |= d > 0.84
if outline:
ink_mask |= _ink_edges(img, thresh=26, thick=3)
# speckle: lost ink and stray ink, like a worn print
noise = RNG.random(d.shape)
ink_mask = (ink_mask & (noise > 0.035)) | (noise < 0.004)
paper_c, ink_c = np.array(paper, np.float32), np.array(ink, np.float32)
out = np.where(ink_mask[..., None], ink_c, paper_c)
out = Image.fromarray(out.astype(np.uint8)).filter(ImageFilter.GaussianBlur(0.35))
out = paper_tex(out, 0.5)
out = creases(out)
return grain(out, 9)
def paper_tex(img, amount=0.5):
tex = Image.open(SRC / 'paper-crumpled.jpg').convert('L').resize(img.size)
tex = ImageOps.autocontrast(tex)
t = np.asarray(tex, dtype=np.float32) / 255
t = 1 - (1 - t) * amount
a = np.asarray(img, dtype=np.float32) * t[..., None]
return Image.fromarray(np.clip(a, 0, 255).astype(np.uint8))
def popart(img, colors=((230, 40, 45), (255, 214, 0), (0, 160, 220), (250, 245, 230)), cell=8):
"""Comic pop-art: flat colour zones, Ben-Day dots, heavy black outlines."""
base = img.filter(ImageFilter.MedianFilter(5))
base = ImageEnhance.Color(base).enhance(1.6)
pal = np.array(colors, dtype=np.float32)
a = np.asarray(base, dtype=np.float32)
idx = ((a[:, :, None, :] - pal[None, None]) ** 2).sum(-1).argmin(-1)
flat = pal[idx]
lum = np.asarray(img.convert('L'), dtype=np.float32) / 255
dots = _halftone_mask(np.clip((0.75 - lum) * 1.4, 0, 1), cell=cell, angle=15)
flat = np.where(dots[..., None], flat * 0.55, flat)
flat = np.where((lum < 0.16)[..., None], 20, flat)
edges = _ink_edges(img, thresh=20, thick=5)
flat = np.where(edges[..., None], 18, flat)
return grain(Image.fromarray(np.clip(flat, 0, 255).astype(np.uint8)), 6)
ASCII_RAMP = ' .:-=+*#%@'
def ascii_art(img, cols=72, fg=(120, 255, 160), bg=(6, 14, 9), font_px=14, ramp=ASCII_RAMP, color=False):
"""Redraw the photo as monospaced characters (terminal style)."""
from PIL import ImageDraw, ImageFont
font = None
for f in ('/usr/share/fonts/truetype/liberation/LiberationMono-Bold.ttf',
'/Library/Fonts/Menlo.ttc', '/System/Library/Fonts/Menlo.ttc', 'C:/Windows/Fonts/consolab.ttf'):
if Path(f).exists():
font = ImageFont.truetype(f, font_px)
break
font = font or ImageFont.load_default(size=font_px)
cw = font.getbbox('M')[2]
ch = int(font_px * 1.15)
rows = max(1, int(cols * img.height / img.width * cw / ch))
small = ImageOps.autocontrast(img.resize((cols, rows), Image.BOX), cutoff=2)
small = ImageEnhance.Contrast(small).enhance(1.4)
lum = np.asarray(small.convert('L'), dtype=np.float32) / 255
rgb = np.asarray(small, dtype=np.uint8)
out = Image.new('RGB', (cols * cw, rows * ch), bg)
draw = ImageDraw.Draw(out)
n = len(ramp) - 1
if sum(bg) > 382: # light paper: dark ink should mark the dark areas
lum = 1 - lum
for r in range(rows):
for c in range(cols):
v = lum[r, c]
char = ramp[int(v * n)]
if char != ' ':
col = tuple(int(x) for x in rgb[r, c]) if color else fg
draw.text((c * cw, r * ch), char, font=font, fill=col)
return out
LOOKS = {'toon': toon, 'pixel': pixel, 'xerox': xerox, 'riso': riso, 'vintage': vintage,
'jsr': jsr, 'popart': popart, 'ascii': ascii_art}
# (source, look, width, kwargs)
RECIPES = [
@@ -187,6 +313,14 @@ RECIPES = [
('cta-sign', 'vintage', 1400, {}),
('pedalboard', 'riso', 1000, {'ink_a': (226, 126, 166), 'ink_b': (20, 20, 18)}),
('cloud', 'xerox', 700, {}),
# street-poster set (stand-ins until the new stock photos are sourced)
('motorcycle', 'jsr', 1100, {}),
('guitar-strat', 'jsr', 900, {'ink': (30, 60, 140), 'paper': (240, 228, 200)}),
('cta-sign', 'popart', 900, {}),
('guitar-strat', 'popart', 900, {}),
('synth', 'jsr', 900, {'ink': (150, 30, 40), 'paper': (245, 222, 180)}),
('cassette', 'ascii', 900, {}),
('tv', 'ascii', 800, {'fg': (46, 92, 44), 'bg': (226, 233, 150)}),
]