36 lines
1.2 KiB
Python
36 lines
1.2 KiB
Python
from PIL import Image
|
|
from PIL import ImageFont
|
|
from PIL import ImageDraw
|
|
|
|
# Colors
|
|
BLACK = (0, 0, 0)
|
|
GREY = (155, 155, 155)
|
|
|
|
def write_card(text):
|
|
text = text.upper()
|
|
img = Image.open("img/template_carte_mot.jpg")
|
|
draw = ImageDraw.Draw(img)
|
|
# font = ImageFont.truetype(<font-file>, <font-size>)
|
|
regularFont = ImageFont.truetype("font/OpenSans-Regular.ttf", 32)
|
|
boldFont = ImageFont.truetype("font/OpenSans-Bold.ttf", 64)
|
|
|
|
# Main text
|
|
draw.text((65, 185), text, BLACK, font=boldFont)
|
|
|
|
# Reversed text
|
|
text_position = (20, 175)
|
|
|
|
# Get the size of the rotated text
|
|
rotated_text_img = Image.new("RGBA", (300, 50), (0, 0, 0, 0))
|
|
rotated_text_draw = ImageDraw.Draw(rotated_text_img)
|
|
rotated_text_draw.text((30, 0), text, GREY, font=regularFont)
|
|
rotated_text_img = rotated_text_img.rotate(180, expand=True)
|
|
rotated_text_width, rotated_text_height = rotated_text_img.size
|
|
|
|
# Calculate the adjusted position for pasting the rotated text
|
|
adjusted_position = (text_position[0], text_position[1] - rotated_text_height)
|
|
|
|
# Paste the rotated text onto the image
|
|
img.paste(rotated_text_img, adjusted_position, rotated_text_img)
|
|
|
|
img.save(f"img/results/{text}.jpg")
|