from PIL import Image, ImageDraw, ImageFont
# Retrieve text input from user
text = input("Enter your text: ")
# Set up image object with dimensions, resolution, and background color
img_width = 400
img_height = 300
img = Image.new('RGB', (img_width, img_height), color='white')
# Set up text styling and formatting
font = ImageFont.truetype("arial.ttf", 36)
text_color = (0, 0, 0)
text_align = 'center'
# Use ImageDraw to render text onto image
draw = ImageDraw.Draw(img)
text_width, text_height = draw.textsize(text, font)
text_x = (img_width - text_width) / 2
text_y = (img_height - text_height) / 2
draw.text((text_x, text_y), text, fill=text_color, font=font, align=text_align)
# Save final image as PNG file
img.save('output.png')
Comments
Post a Comment