✨
This commit is contained in:
@ -1,13 +1,16 @@
|
||||
import os
|
||||
import random
|
||||
from PIL import Image, ImageFont, ImageDraw
|
||||
import lorem
|
||||
|
||||
from font_game import gen_id, IMAGE_SIZE, IMAGE_BACKGROUND, MARGINS, FONT_COLOR
|
||||
|
||||
def gen_image(font: ImageFont.ImageFont) -> str:
|
||||
img = Image.new("RGB", IMAGE_SIZE, IMAGE_BACKGROUND)
|
||||
image_mult = random.uniform(0.8,1.2)
|
||||
image_size = (int(IMAGE_SIZE[0]*image_mult), int(IMAGE_SIZE[1]*image_mult))
|
||||
img = Image.new("RGB", image_size, IMAGE_BACKGROUND)
|
||||
drawer = ImageDraw.Draw(img)
|
||||
text_width = IMAGE_SIZE[0] - 2 * MARGINS
|
||||
text_width = int((IMAGE_SIZE[0] - 2 * MARGINS)*image_mult)
|
||||
text = lorem.sentence()
|
||||
text_list = []
|
||||
line = ""
|
||||
@ -21,7 +24,7 @@ def gen_image(font: ImageFont.ImageFont) -> str:
|
||||
text_list.append(line)
|
||||
|
||||
drawer.text(
|
||||
(MARGINS, MARGINS),
|
||||
(int(MARGINS*image_mult), int(MARGINS*image_mult)),
|
||||
'\n'.join(text_list),
|
||||
FONT_COLOR,
|
||||
font,
|
||||
|
Reference in New Issue
Block a user