Created
December 4, 2024 18:09
-
-
Save jazlopez/aa6bb2f0e59f074d38ebddae4e85c2d0 to your computer and use it in GitHub Desktop.
Add text to an image using python and pillow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image, ImageDraw, ImageFont | |
original_image = "test.jpg" | |
modified_image = "modified.jpg" | |
text="YOUR TEST GOES HERE" | |
path_font = "/System/Library/Fonts/Supplemental/Verdana.ttf" # modify to your system | |
font_size = 80 # modify to your needs | |
text_position = (0,0) # modify to your needs | |
text_color = (255, 255, 255) # modify rgb color | |
image = Image.open(original_image) | |
draw = ImageDraw.Draw(image) | |
# configure your font | |
configured_font = ImageFont.truetype(path_font, size=font_size) | |
# add text to image | |
draw.text(text_position, text, font=configured_font, fill=text_color) | |
# save image | |
image.save(modified_image) | |
print(f"Check your image: {modified_image}!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment