Restore MOTD-style ASCII wallpaper
This commit is contained in:
@@ -10,20 +10,15 @@ import os
|
|||||||
|
|
||||||
W, H = 1920, 1080
|
W, H = 1920, 1080
|
||||||
|
|
||||||
GLYPHS = {
|
ASCII_ART = [
|
||||||
'E': ["11111", "10000", "11110", "10000", "10000", "10000", "11111"],
|
" ███████╗ █████╗ ███████╗██╗ ██╗ ██████╗ ███████╗███████╗",
|
||||||
'A': ["01110", "10001", "10001", "11111", "10001", "10001", "10001"],
|
" ██╔════╝██╔══██╗██╔════╝╚██╗ ██╔╝ ██╔══██╗██╔════╝██╔════╝",
|
||||||
'S': ["01111", "10000", "10000", "01110", "00001", "00001", "11110"],
|
" █████╗ ███████║███████╗ ╚████╔╝ █████╗██████╔╝█████╗ █████╗",
|
||||||
'Y': ["10001", "10001", "01010", "00100", "00100", "00100", "00100"],
|
" ██╔══╝ ██╔══██║╚════██║ ╚██╔╝ ╚════╝██╔══██╗██╔══╝ ██╔══╝",
|
||||||
'B': ["11110", "10001", "10001", "11110", "10001", "10001", "11110"],
|
" ███████╗██║ ██║███████║ ██║ ██████╔╝███████╗███████╗",
|
||||||
'-': ["00000", "00000", "11111", "00000", "00000", "00000", "00000"],
|
" ╚══════╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═════╝ ╚══════╝╚══════╝",
|
||||||
}
|
]
|
||||||
|
SUBTITLE = " Hardware Audit LiveCD"
|
||||||
TITLE = "EASY-BEE"
|
|
||||||
SUBTITLE = "Hardware Audit LiveCD"
|
|
||||||
CELL = 30
|
|
||||||
GLYPH_GAP = 18
|
|
||||||
ROW_GAP = 6
|
|
||||||
|
|
||||||
FG = (0xF6, 0xD0, 0x47)
|
FG = (0xF6, 0xD0, 0x47)
|
||||||
FG_DIM = (0xD4, 0xA9, 0x1C)
|
FG_DIM = (0xD4, 0xA9, 0x1C)
|
||||||
@@ -31,6 +26,12 @@ SHADOW = (0x5E, 0x47, 0x05)
|
|||||||
SUB = (0x96, 0x7A, 0x17)
|
SUB = (0x96, 0x7A, 0x17)
|
||||||
BG = (0x05, 0x05, 0x05)
|
BG = (0x05, 0x05, 0x05)
|
||||||
|
|
||||||
|
MONO_FONT_CANDIDATES = [
|
||||||
|
'/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf',
|
||||||
|
'/usr/share/fonts/truetype/liberation2/LiberationMono-Bold.ttf',
|
||||||
|
'/usr/share/fonts/truetype/liberation/LiberationMono-Bold.ttf',
|
||||||
|
'/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf',
|
||||||
|
]
|
||||||
SUB_FONT_CANDIDATES = [
|
SUB_FONT_CANDIDATES = [
|
||||||
'/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf',
|
'/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf',
|
||||||
'/usr/share/fonts/truetype/liberation2/LiberationSans-Bold.ttf',
|
'/usr/share/fonts/truetype/liberation2/LiberationSans-Bold.ttf',
|
||||||
@@ -39,43 +40,34 @@ SUB_FONT_CANDIDATES = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def load_font(size):
|
def load_font(candidates, size):
|
||||||
for path in SUB_FONT_CANDIDATES:
|
for path in candidates:
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
return ImageFont.truetype(path, size)
|
return ImageFont.truetype(path, size)
|
||||||
return ImageFont.load_default()
|
return ImageFont.load_default()
|
||||||
|
|
||||||
|
|
||||||
def glyph_width(ch):
|
def mono_metrics(font):
|
||||||
return len(GLYPHS[ch][0])
|
probe = Image.new('L', (W, H), 0)
|
||||||
|
draw = ImageDraw.Draw(probe)
|
||||||
|
char_w = int(round(draw.textlength("M", font=font)))
|
||||||
|
bb = draw.textbbox((0, 0), "Mg", font=font)
|
||||||
|
char_h = bb[3] - bb[1]
|
||||||
|
return char_w, char_h
|
||||||
|
|
||||||
|
|
||||||
def render_logo_mask():
|
def render_ascii_mask(font, lines, char_w, char_h, line_gap):
|
||||||
width_cells = 0
|
width = max(len(line) for line in lines) * char_w
|
||||||
for idx, ch in enumerate(TITLE):
|
height = len(lines) * char_h + line_gap * (len(lines) - 1)
|
||||||
width_cells += glyph_width(ch)
|
mask = Image.new('L', (width, height), 0)
|
||||||
if idx != len(TITLE) - 1:
|
|
||||||
width_cells += 1
|
|
||||||
mask_w = width_cells * CELL + (len(TITLE) - 1) * GLYPH_GAP
|
|
||||||
mask_h = 7 * CELL + 6 * ROW_GAP
|
|
||||||
mask = Image.new('L', (mask_w, mask_h), 0)
|
|
||||||
draw = ImageDraw.Draw(mask)
|
draw = ImageDraw.Draw(mask)
|
||||||
|
for row, line in enumerate(lines):
|
||||||
cx = 0
|
y = row * (char_h + line_gap)
|
||||||
for idx, ch in enumerate(TITLE):
|
for col, ch in enumerate(line):
|
||||||
glyph = GLYPHS[ch]
|
if ch == ' ':
|
||||||
for row_idx, row in enumerate(glyph):
|
|
||||||
for col_idx, cell in enumerate(row):
|
|
||||||
if cell != '1':
|
|
||||||
continue
|
continue
|
||||||
x0 = cx + col_idx * CELL
|
x = col * char_w
|
||||||
y0 = row_idx * (CELL + ROW_GAP)
|
draw.text((x, y), ch, font=font, fill=255)
|
||||||
x1 = x0 + CELL - 4
|
|
||||||
y1 = y0 + CELL - 4
|
|
||||||
draw.rounded_rectangle((x0, y0, x1, y1), radius=4, fill=255)
|
|
||||||
cx += glyph_width(ch) * CELL
|
|
||||||
if idx != len(TITLE) - 1:
|
|
||||||
cx += CELL + GLYPH_GAP
|
|
||||||
return mask
|
return mask
|
||||||
|
|
||||||
|
|
||||||
@@ -90,20 +82,22 @@ glow_draw.ellipse((520, 340, 1400, 760), fill=(255, 190, 40, 36))
|
|||||||
glow = glow.filter(ImageFilter.GaussianBlur(60))
|
glow = glow.filter(ImageFilter.GaussianBlur(60))
|
||||||
img = Image.alpha_composite(img.convert('RGBA'), glow)
|
img = Image.alpha_composite(img.convert('RGBA'), glow)
|
||||||
|
|
||||||
logo_mask = render_logo_mask()
|
font_logo = load_font(MONO_FONT_CANDIDATES, 64)
|
||||||
|
char_w, char_h = mono_metrics(font_logo)
|
||||||
|
logo_mask = render_ascii_mask(font_logo, ASCII_ART, char_w, char_h, 8)
|
||||||
logo_w, logo_h = logo_mask.size
|
logo_w, logo_h = logo_mask.size
|
||||||
logo_x = (W - logo_w) // 2
|
logo_x = (W - logo_w) // 2
|
||||||
logo_y = 290
|
logo_y = 270
|
||||||
|
|
||||||
shadow_mask = logo_mask.filter(ImageFilter.GaussianBlur(2))
|
shadow_mask = logo_mask.filter(ImageFilter.GaussianBlur(2))
|
||||||
img.paste(SHADOW, (logo_x + 16, logo_y + 14), shadow_mask)
|
img.paste(SHADOW, (logo_x + 16, logo_y + 14), shadow_mask)
|
||||||
img.paste(FG_DIM, (logo_x + 8, logo_y + 7), logo_mask)
|
img.paste(FG_DIM, (logo_x + 8, logo_y + 7), logo_mask)
|
||||||
img.paste(FG, (logo_x, logo_y), logo_mask)
|
img.paste(FG, (logo_x, logo_y), logo_mask)
|
||||||
|
|
||||||
font_sub = load_font(30)
|
font_sub = load_font(SUB_FONT_CANDIDATES, 30)
|
||||||
sub_bb = draw.textbbox((0, 0), SUBTITLE, font=font_sub)
|
sub_bb = draw.textbbox((0, 0), SUBTITLE, font=font_sub)
|
||||||
sub_x = (W - (sub_bb[2] - sub_bb[0])) // 2
|
sub_x = (W - (sub_bb[2] - sub_bb[0])) // 2
|
||||||
sub_y = logo_y + logo_h + 54
|
sub_y = logo_y + logo_h + 48
|
||||||
draw = ImageDraw.Draw(img)
|
draw = ImageDraw.Draw(img)
|
||||||
draw.text((sub_x + 2, sub_y + 2), SUBTITLE, font=font_sub, fill=(35, 28, 6))
|
draw.text((sub_x + 2, sub_y + 2), SUBTITLE, font=font_sub, fill=(35, 28, 6))
|
||||||
draw.text((sub_x, sub_y), SUBTITLE, font=font_sub, fill=SUB)
|
draw.text((sub_x, sub_y), SUBTITLE, font=font_sub, fill=SUB)
|
||||||
|
|||||||
Reference in New Issue
Block a user