fix png, add emoji

This commit is contained in:
Mylloon 2024-09-28 23:24:05 +02:00
parent b763933132
commit 750b69843f
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 53 additions and 35 deletions

BIN
images/love.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
images/work.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

66
main.py
View file

@ -2,7 +2,9 @@ from random import choice
from os.path import join from os.path import join
from PIL import Image, ImageDraw, ImageFont from PIL import Image, ImageDraw, ImageFont
zodiac_signs = [
def generate_horoscope() -> dict[str, dict[str, str]]:
zodiac_signs = [
"Belier", "Belier",
"Cancer", "Cancer",
"Balance", "Balance",
@ -15,47 +17,63 @@ zodiac_signs = [
"Vierge", "Vierge",
"Sagittaire", "Sagittaire",
"Poissons", "Poissons",
] ]
def generate_horoscope():
horoscope = {} horoscope = {}
for sign in zodiac_signs: for sign in zodiac_signs:
heart = choice(["+++", "++", "+", "-", "- -"]) love = choice(["+++", "++", "+", "-", "- -"])
work = choice(["+++", "++", "+", "-", "- -"]) work = choice(["+++", "++", "+", "-", "- -"])
horoscope[sign] = {"heart": heart, "work": work} horoscope[sign] = {"love": love, "work": work}
return horoscope return horoscope
def create_horoscope_image(horoscope): def create_horoscope_image(horoscope: dict[str, dict[str, str]]):
img_width, img_height = 1050, 450 img_width, img_height = 1200, 425
image = Image.new("RGBA", (img_width, img_height), color=(255, 255, 255, 0)) image = Image.new("RGBA", (img_width, img_height), color=(255, 255, 255, 0))
draw = ImageDraw.Draw(image) draw = ImageDraw.Draw(image)
font = ImageFont.load_default(24) size_emoji = (30, 30)
font_sign = ImageFont.load_default(24)
font_prediction = ImageFont.load_default(40)
x, y = 10, 10 x, y = 10, 10
for sign, prediction in horoscope.items(): for sign, prediction in horoscope.items():
sign_image = Image.open(join("images", f"{sign.lower()}.png")).convert("RGBA") sign_image = Image.open(join("images", f"{sign.lower()}.png")).convert("RGBA")
sign_image.thumbnail((100, 100)) sign_image.thumbnail((100, 105))
image.paste(sign_image, (x, y), sign_image) image.paste(sign_image, (x + 20, y), sign_image)
draw.text((x + 110, y), sign, fill=(0, 0, 0, 255), font=font) # Sign text
text_img = Image.new("RGBA", (135, 24), (255, 255, 255, 0))
text_draw = ImageDraw.Draw(text_img)
text_draw.text((0, 0), f"{sign:^15}", font=font_sign, fill="black")
text_draw = text_img.rotate(90, expand=True)
image.paste(text_draw, (x - 10, y - 10), text_draw)
# Love prediction
love = Image.open(join("images", "love.png")).convert("RGBA")
love.thumbnail(size_emoji)
image.paste(love, (x + 125, y + 20), love)
draw.text( draw.text(
(x + 110, y + 40), (x + 160, y + 10),
f"♥: {prediction['heart']}", prediction["love"],
fill=(255, 0, 0, 255), fill="black",
font=font, font=font_prediction,
)
draw.text(
(x + 110, y + 80),
f"💼: {prediction['work']}",
fill=(0, 0, 255, 255),
font=font,
) )
x += 250 # Work prediction
if x > 900: work = Image.open(join("images", "work.png")).convert("RGBA")
work.thumbnail(size_emoji)
image.paste(work, (x + 125, y + 60), work)
draw.text(
(x + 160, y + 50),
prediction["work"],
fill="black",
font=font_prediction,
)
x += 320
if x > 1200:
x = 10 x = 10
y += 150 y += 150