from PIL import Image, ImageDraw, ImageFont
def text_to_image(input_text, output_path):
# Create a blank image with a white background
image_size = (500, 500)
image = Image.new("RGB", image_size, "white")
draw = ImageDraw.Draw(image)
# Specify font style and size
font_size = 20
font = ImageFont.load_default()
# Define text position
text_position = (50, 50)
# Add text to the image
draw.text(text_position, input_text, font=font, fill="black")
# Save the image
image.save(output_path)
# Example usage:
user_text = "Hello, AI!"
output_image_path = "output_image.png"
text_to_image(user_text, output_image_path)
Comments
Post a Comment