Untitled

 avatar
unknown
plain_text
2 years ago
886 B
26
Indexable
from PIL import Image, ImageDraw, ImageFont

# Load the image
image_path = "/mnt/data/file-5f3GXBXKTosau0oQ8tP6oMyZ"
image = Image.open(image_path)

# Prepare the text and font
text = "FIND SOMEONE WHO GROWS FLOWERS IN THE DARKEST PARTS OF YOU"
font_path = "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"  # Use a default font
font_size = 24
font = ImageFont.truetype(font_path, font_size)

# Create a drawing context
draw = ImageDraw.Draw(image)

# Calculate text size and position
text_width, text_height = draw.textsize(text, font=font)
image_width, image_height = image.size
text_x = (image_width - text_width) / 2
text_y = image_height / 4  # Position it in the upper part of the image

# Add text to the image
draw.text((text_x, text_y), text, font=font, fill="white")

# Save the edited image
output_path = "/mnt/data/edited_image.png"
image.save(output_path)

output_path
Editor is loading...
Leave a Comment