Add nerd glasses and the ...because he was bored... subtitle to the loading screen
This commit is contained in:
+39
-28
@@ -14,14 +14,19 @@ from PIL import Image, ImageDraw, ImageFilter, ImageFont
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('raw', type=pathlib.Path, help='raw generated image (magenta background)')
|
||||
parser.add_argument('--title', default='MatGames')
|
||||
parser.add_argument('--subtitle', default='"...because he was bored..."',
|
||||
help='second line under the title; empty string for none')
|
||||
parser.add_argument('--subtitle-height', type=int, default=100)
|
||||
parser.add_argument('--bottom-padding', type=int, default=30,
|
||||
help='empty band under the text: the shell progress bar sits there')
|
||||
parser.add_argument('--canvas', type=int, default=1024)
|
||||
parser.add_argument('--title-height', type=int, default=190)
|
||||
parser.add_argument('--bottom-fade', type=int, default=50,
|
||||
help='soften the generator frame cut at the bottom of the bust')
|
||||
parser.add_argument('--colors', type=int, default=256,
|
||||
help='palette colors for the shipped PNG; 0 keeps 32-bit RGBA')
|
||||
parser.add_argument('--generated-from', type=pathlib.Path, default=None,
|
||||
help='pre-edit generation this file was derived from, for provenance')
|
||||
parser.add_argument('--provenance', action='append', type=pathlib.Path, default=[],
|
||||
help='earlier files of the generation/edit chain, in order; repeatable')
|
||||
args = parser.parse_args()
|
||||
args.raw = args.raw.resolve()
|
||||
root = pathlib.Path(__file__).resolve().parents[1]
|
||||
@@ -70,27 +75,34 @@ if args.bottom_fade > 0:
|
||||
|
||||
# ---------------------------------------------------------------- composition
|
||||
canvas_width = args.canvas
|
||||
title_area = args.title_height
|
||||
title_area = args.title_height + (args.subtitle_height if args.subtitle else 0)
|
||||
scale = (canvas_width - 2 * 40) / mascot.width
|
||||
mascot = mascot.resize((round(mascot.width * scale), round(mascot.height * scale)), Image.LANCZOS)
|
||||
height = mascot.height + title_area
|
||||
height = mascot.height + title_area + args.bottom_padding
|
||||
canvas = Image.new('RGBA', (canvas_width, height), (0, 0, 0, 0))
|
||||
canvas.alpha_composite(mascot, ((canvas_width - mascot.width) // 2, 0))
|
||||
|
||||
font_size = int(title_area * 0.95)
|
||||
font = ImageFont.truetype(str(font_path), font_size)
|
||||
text = args.title
|
||||
while font.getbbox(text)[2] - font.getbbox(text)[0] > canvas_width - 60 and font_size > 8:
|
||||
font_size -= 2
|
||||
font = ImageFont.truetype(str(font_path), font_size)
|
||||
box = font.getbbox(text)
|
||||
text_width = box[2] - box[0]
|
||||
position = ((canvas_width - text_width) // 2 - box[0], mascot.height + (title_area - box[3]) // 2 - box[1])
|
||||
glow = Image.new('RGBA', canvas.size, (0, 0, 0, 0))
|
||||
ImageDraw.Draw(glow).text(position, text, font=font, fill=(255, 150, 20, 190))
|
||||
glow = glow.filter(ImageFilter.GaussianBlur(9))
|
||||
canvas.alpha_composite(glow)
|
||||
ImageDraw.Draw(canvas).text(position, text, font=font, fill=(255, 196, 64, 255))
|
||||
|
||||
def _draw_line(text: str, block_top: int, block_height: int, size: int,
|
||||
glow_color: tuple, text_color: tuple, blur: int) -> None:
|
||||
font = ImageFont.truetype(str(font_path), size)
|
||||
while font.getbbox(text)[2] - font.getbbox(text)[0] > canvas_width - 60 and size > 8:
|
||||
size -= 2
|
||||
font = ImageFont.truetype(str(font_path), size)
|
||||
box = font.getbbox(text)
|
||||
position = ((canvas_width - (box[2] - box[0])) // 2 - box[0],
|
||||
block_top + (block_height - box[3]) // 2 - box[1])
|
||||
glow = Image.new('RGBA', canvas.size, (0, 0, 0, 0))
|
||||
ImageDraw.Draw(glow).text(position, text, font=font, fill=glow_color)
|
||||
canvas.alpha_composite(glow.filter(ImageFilter.GaussianBlur(blur)))
|
||||
ImageDraw.Draw(canvas).text(position, text, font=font, fill=text_color)
|
||||
|
||||
|
||||
_draw_line(args.title, mascot.height, args.title_height, int(args.title_height * 0.95),
|
||||
(255, 150, 20, 190), (255, 196, 64, 255), 9)
|
||||
if args.subtitle:
|
||||
_draw_line(args.subtitle, mascot.height + args.title_height, args.subtitle_height,
|
||||
int(args.subtitle_height * 0.8), (255, 150, 20, 150), (255, 176, 58, 240), 6)
|
||||
|
||||
out = branding / 'boot_splash.png'
|
||||
if args.colors > 0:
|
||||
@@ -111,23 +123,22 @@ manifest.update({
|
||||
'prompt': ('single cartoon zombie head-and-bust mascot, unsettling wide grin, thumbs up, '
|
||||
'2D cartoon style with bold outlines, flat magenta chroma-key background, '
|
||||
'no text and no logo; then edited to a bald scalp with a sparse hair fringe '
|
||||
'on the sides only'),
|
||||
'on the sides only, then edited again to wear thick nerd glasses'),
|
||||
'terms_note': ('generated from no third-party source material; the provider terms do not claim '
|
||||
'ownership of the output. The generator emits no real alpha channel, so the '
|
||||
'background is keyed out locally by this script.'),
|
||||
},
|
||||
'chroma_key': {'background_rgb': list(background), 'transparent_below': T0, 'opaque_above': T1},
|
||||
'title': {'text': args.title, 'font': 'tools/branding/fonts/VT323-Regular.ttf',
|
||||
'title': {'text': args.title, 'subtitle': args.subtitle,
|
||||
'font': 'tools/branding/fonts/VT323-Regular.ttf',
|
||||
'license': 'SIL Open Font License 1.1 (tools/branding/fonts/OFL.txt)'},
|
||||
'bottom_fade_px': args.bottom_fade,
|
||||
'bottom_padding_px': args.bottom_padding,
|
||||
})
|
||||
if args.generated_from is not None:
|
||||
chain = manifest.get('mascot_derived_from', [])
|
||||
manifest['mascot_derived_from'] = chain + [{
|
||||
'file': str(args.generated_from.resolve().relative_to(root)),
|
||||
'sha256': hashlib.sha256(args.generated_from.read_bytes()).hexdigest(),
|
||||
'edit': 'AI edit (agy_edit): keep face, grin, thumbs up, shirt, pose and flat background; '
|
||||
'change the hair to a bald scalp with a sparse fringe on the sides only',
|
||||
}]
|
||||
chain = list(args.provenance) + [args.raw]
|
||||
manifest['mascot_provenance'] = [
|
||||
{'file': str(path.resolve().relative_to(root)),
|
||||
'sha256': hashlib.sha256(path.read_bytes()).hexdigest()} for path in chain]
|
||||
manifest.pop('mascot_derived_from', None)
|
||||
(source_tools / 'manifest.json').write_text(json.dumps(manifest, indent=2) + '\n')
|
||||
print(out, canvas.size, canvas.mode, 'mascot', mascot.size)
|
||||
|
||||
Reference in New Issue
Block a user