hitsounds/spelunker/generate_skin.py

97 lines
2.8 KiB
Python
Raw Normal View History

2023-05-19 22:55:53 +00:00
from PIL import Image, ImageDraw, ImageFont
from pathlib import Path
out_dir = r"C:\Users\mzhan\AppData\Local\osu!\Songs\1145452 Unknown Artist - Spelunker"
def empty(path):
im = Image.new("RGBA", (1, 1))
im.save(path)
hitcircle = Image.new("RGBA", (128, 128))
draw = ImageDraw.Draw(hitcircle)
draw.ellipse((5, 5, 118 + 5, 118 + 5), fill="white")
hitcircleoverlay = Image.new("RGBA", (128, 128))
draw = ImageDraw.Draw(hitcircleoverlay)
draw.ellipse((5, 5, 118 + 5, 118 + 5), outline="white", width=8)
approachcircle = Image.new("RGBA", (126, 126))
draw2 = ImageDraw.Draw(approachcircle)
size = 4
draw2.ellipse((size, size, 118 + size, 118 + size), outline="white", width=6)
scorebarbg = Image.new("RGBA", (400, 40))
draw4 = ImageDraw.Draw(scorebarbg)
draw4.rectangle((0, 10, 400, 40), fill="yellow")
scorebarcolor = Image.new("RGBA", (390, 40))
draw5 = ImageDraw.Draw(scorebarcolor)
draw5.rectangle((0, 4, 400, 20), fill="orange")
def get_text_dimensions(text_string, font):
# https://stackoverflow.com/a/46220683/9263761
ascent, descent = font.getmetrics()
text_width = font.getmask(text_string).getbbox()[2]
text_height = font.getmask(text_string).getbbox()[3] + descent
return (text_width, text_height)
def thefont(size=None):
if size is None:
size = 48
return ImageFont.FreeTypeFont(r"C:\WINDOWS\FONTS\SIMFANG.TTF", size)
def gentext(text, path, font=None, size=None, **kwargs):
if font is None:
font = thefont(size=size)
width, height = get_text_dimensions(text, font)
height += 2
im = Image.new("RGBA", (width, height))
draw3 = ImageDraw.Draw(im)
draw3.fontmode = "1"
draw3.text((0, 0), text, font=font, **kwargs)
im.save(path)
def gen2text(text, path, font=None, size=None, **kwargs):
if size is None:
size = 48
p = Path(path)
gentext(text, p, font=font, **kwargs)
pname = p.name.rstrip(".png")
p2 = p.with_name(pname + "@2x.png")
gentext(text, p2, font=font, size=size * 2, **kwargs)
# Scorebar set
scorebarbg.save(f"{out_dir}/scorebar-bg.png")
scorebarcolor.save(f"{out_dir}/scorebar-colour.png")
# Hitcircle set
hitcircle.save(f"{out_dir}/hitcircle.png")
hitcircleoverlay.save(f"{out_dir}/hitcircleoverlay.png")
hitcircleoverlay.save(f"{out_dir}/sliderstartcircleoverlay.png")
empty(f"{out_dir}/sliderendcircleoverlay.png")
approachcircle.save(f"{out_dir}/approachcircle.png")
hitcircle.save(f"{out_dir}/sliderstartcircle.png")
# Hitcircle number set
for i in range(10):
gentext(str(i), f"{out_dir}/default-{i}.png", fill="white")
# Hitburst set
gen2text("Zzz", f"{out_dir}/hit0.png")
# gen2text("無謀な……", f"{out_dir}/hit100k.png")
# gen2text("え?俺勝っちゃったの?", f"{out_dir}/hit300g.png")
# gen2text("ヤッフー!!", f"{out_dir}/hit300k.png")