Spaces:
Sleeping
Sleeping
from PIL import Image, ImageDraw, ImageFont | |
# Dimensões da imagem | |
width, height = 576, 1024 | |
# Criar uma imagem branca | |
image = Image.new('RGB', (width, height), color='white') | |
# Criar um objeto de desenho | |
draw = ImageDraw.Draw(image) | |
# Carregar uma fonte (certifique-se de que a fonte está disponível no seu sistema) | |
try: | |
font = ImageFont.truetype("arial.ttf", 40) | |
except IOError: | |
font = ImageFont.load_default() | |
# Texto a ser adicionado à imagem | |
text = "Este é um exemplo de texto em uma imagem." | |
# Calcular a posição do texto para centralizá-lo | |
bbox = draw.textbbox((0, 0), text, font=font) | |
text_width = bbox[2] - bbox[0] | |
text_height = bbox[3] - bbox[1] | |
text_x = (width - text_width) / 2 | |
text_y = (height - text_height) / 2 | |
# Adicionar texto à imagem | |
draw.text((text_x, text_y), text, font=font, fill='black') | |
# Salvar a imagem | |
image.save('text_image.png') | |
# Exibir a imagem | |
image.show() |