mirror of
https://github.com/velocitatem/PHANTOM.git
synced 2026-05-31 16:43:36 +00:00
hidef banner rendering
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 41 KiB After Width: | Height: | Size: 84 KiB |
@@ -1,14 +1,24 @@
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
text = open("banner.txt", "r", encoding="utf-8").read()
|
||||
font = ImageFont.truetype("DejaVuSansMono.ttf", 18)
|
||||
|
||||
dummy = Image.new("RGB", (1, 1))
|
||||
scale = 4 # 2–6 is typical
|
||||
pad = 10
|
||||
font_px = 18
|
||||
|
||||
font = ImageFont.truetype("DejaVuSansMono.ttf", font_px * scale)
|
||||
|
||||
# Measure at high res
|
||||
dummy = Image.new("RGB", (1, 1), "white")
|
||||
d = ImageDraw.Draw(dummy)
|
||||
bbox = d.multiline_textbbox((0, 0), text, font=font)
|
||||
w, h = bbox[2] - bbox[0], bbox[3] - bbox[1]
|
||||
|
||||
img = Image.new("RGB", (w+20, h+20), "white")
|
||||
d = ImageDraw.Draw(img)
|
||||
d.multiline_text((10,10), text, font=font, fill="black")
|
||||
img.save("banner.png")
|
||||
# Render at high res
|
||||
hi = Image.new("RGB", (w + 2*pad*scale, h + 2*pad*scale), "white")
|
||||
d = ImageDraw.Draw(hi)
|
||||
d.multiline_text((pad*scale, pad*scale), text, font=font, fill="black")
|
||||
|
||||
# Downscale with a good filter
|
||||
out = hi.resize((hi.width // scale, hi.height // scale), resample=Image.Resampling.LANCZOS)
|
||||
out.save("banner.png", dpi=(300, 300))
|
||||
|
||||
Reference in New Issue
Block a user