Untitled

 avatar
unknown
python
a year ago
991 B
7
Indexable
om PIL import Image
from PIL import ImageDraw
from PIL import ImageFont

# Load the image
image = Image.open("image.jpg")

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

# Load a font
font = ImageFont.truetype("arial.ttf", 30)

# Define the text to be added
text = "CHATPATI DUNIA"
text2 = "ghar ka taste"

# Define the text color
text_color = (255, 255, 255)

# Calculate the text width and height
text_width, text_height = draw.textsize(text, font=font)
text2_width, text2_height = draw.textsize(text2, font=font)

# Define the position of the text
text_x = (image.width - text_width) / 2
text_y = (image.height - text_height) / 2 - 50

text2_x = (image.width - text2_width) / 2
text2_y = (image.height - text2_height) / 2 + 100

# Add the text to the image
draw.text((text_x, text_y), text, fill=text_color, font=font)
draw.text((text2_x, text2_y), text2, fill=text_color, font=font)

# Save the image
image.save("image_with_text.jpg"



Editor is loading...
Leave a Comment