some fixes
This commit is contained in:
parent
f66aa41a1e
commit
b763933132
1 changed files with 39 additions and 38 deletions
69
main.py
69
main.py
|
@ -4,16 +4,16 @@ from PIL import Image, ImageDraw, ImageFont
|
||||||
|
|
||||||
zodiac_signs = [
|
zodiac_signs = [
|
||||||
"Belier",
|
"Belier",
|
||||||
"Taureau",
|
|
||||||
"Gemeaux",
|
|
||||||
"Cancer",
|
"Cancer",
|
||||||
"Lion",
|
|
||||||
"Vierge",
|
|
||||||
"Balance",
|
"Balance",
|
||||||
"Scorpion",
|
|
||||||
"Sagittaire",
|
|
||||||
"Capricorne",
|
"Capricorne",
|
||||||
|
"Taureau",
|
||||||
|
"Lion",
|
||||||
|
"Scorpion",
|
||||||
"Verseau",
|
"Verseau",
|
||||||
|
"Gemeaux",
|
||||||
|
"Vierge",
|
||||||
|
"Sagittaire",
|
||||||
"Poissons",
|
"Poissons",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -21,52 +21,53 @@ zodiac_signs = [
|
||||||
def generate_horoscope():
|
def generate_horoscope():
|
||||||
horoscope = {}
|
horoscope = {}
|
||||||
for sign in zodiac_signs:
|
for sign in zodiac_signs:
|
||||||
heart = choice(["+", "++", "+++", "-", "--"])
|
heart = choice(["+++", "++", "+", "-", "- -"])
|
||||||
work = choice(["+", "++", "+++", "-", "--"])
|
work = choice(["+++", "++", "+", "-", "- -"])
|
||||||
|
|
||||||
if heart.count("+") > 3:
|
|
||||||
heart = "+++"
|
|
||||||
elif heart.count("-") > 2:
|
|
||||||
heart = "--"
|
|
||||||
|
|
||||||
if work.count("+") > 3:
|
|
||||||
work = "+++"
|
|
||||||
elif work.count("-") > 2:
|
|
||||||
work = "--"
|
|
||||||
|
|
||||||
horoscope[sign] = {"heart": heart, "work": work}
|
horoscope[sign] = {"heart": heart, "work": work}
|
||||||
|
|
||||||
return horoscope
|
return horoscope
|
||||||
|
|
||||||
|
|
||||||
def create_horoscope_image(horoscope):
|
def create_horoscope_image(horoscope):
|
||||||
img_width, img_height = 800, 600
|
img_width, img_height = 1050, 450
|
||||||
image = Image.new("RGBA", (img_width, img_height), color="white")
|
image = Image.new("RGBA", (img_width, img_height), color=(255, 255, 255, 0))
|
||||||
draw = ImageDraw.Draw(image, "RGBA")
|
draw = ImageDraw.Draw(image)
|
||||||
|
|
||||||
font = ImageFont.load_default()
|
font = ImageFont.load_default(24)
|
||||||
|
|
||||||
x, y = 20, 20
|
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"))
|
sign_image = Image.open(join("images", f"{sign.lower()}.png")).convert("RGBA")
|
||||||
image.paste(sign_image, (x, y))
|
sign_image.thumbnail((100, 100))
|
||||||
|
image.paste(sign_image, (x, y), sign_image)
|
||||||
|
|
||||||
draw.text((x, y), sign, fill="black", font=font)
|
draw.text((x + 110, y), sign, fill=(0, 0, 0, 255), font=font)
|
||||||
draw.text((x, y + 30), f"♥: {prediction['heart']}", fill="red", font=font)
|
draw.text(
|
||||||
draw.text((x, y + 60), f"💼: {prediction['work']}", fill="blue", font=font)
|
(x + 110, y + 40),
|
||||||
|
f"♥: {prediction['heart']}",
|
||||||
|
fill=(255, 0, 0, 255),
|
||||||
|
font=font,
|
||||||
|
)
|
||||||
|
draw.text(
|
||||||
|
(x + 110, y + 80),
|
||||||
|
f"💼: {prediction['work']}",
|
||||||
|
fill=(0, 0, 255, 255),
|
||||||
|
font=font,
|
||||||
|
)
|
||||||
|
|
||||||
x += 200
|
x += 250
|
||||||
if x > 600:
|
if x > 900:
|
||||||
x = 20
|
x = 10
|
||||||
y += 150
|
y += 150
|
||||||
|
|
||||||
return image
|
return image
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# Generate new horoscope
|
||||||
new_horoscope = generate_horoscope()
|
new_horoscope = generate_horoscope()
|
||||||
|
|
||||||
|
# Create and save the image
|
||||||
horoscope_image = create_horoscope_image(new_horoscope)
|
horoscope_image = create_horoscope_image(new_horoscope)
|
||||||
|
|
||||||
horoscope_image.save("nouvel_horoscope.png")
|
horoscope_image.save("nouvel_horoscope.png")
|
||||||
|
|
||||||
print("Nouvel horoscope généré et sauvegardé sous 'nouvel_horoscope.png'")
|
print("Nouvel horoscope généré et sauvegardé sous 'nouvel_horoscope.png'")
|
||||||
|
|
Loading…
Reference in a new issue