def generate_img(output="", theme={}, text="", resolution=(1920,1080)):
# img = Image.open(backdrop)
img = Image.new("RGB", resolution, theme["background"])
W, H = img.size
logo = Image.open(DEFAULT_DIR+"/assets/logo.png")
colorized_img = ImageOps.colorize(logo.convert("L"), theme["text"], theme["background"])
size = int((W/100)*17)
logo_newsize = colorized_img.resize((size, size), Image.ANTIALIAS)
img.paste(logo_newsize, (int((W-size)/2), int((H-size)/2)))
draw = ImageDraw.Draw(img)
base_font_pixle = int((56/1920)*resolution[0])
font = ImageFont.truetype("DejaVuSansMono.ttf", base_font_pixle)
w, h = font.getsize(text)
text_draw(draw, text, base_font_pixle, img.size, theme)
img.save(output, quality=100)
评论列表
文章目录