- Python Pillow Tutorial
- Python Pillow - Home
- Python Pillow - Overview
- Python Pillow - Environment Setup
- Python Pillow - Using Image Module
- Python Pillow - Working with Images
- Python Pillow - Creating Thumbnails
- Python Pillow - Merging Images
- Python Pillow - Blur an Image
- Python Pillow - Cropping an Image
- Python Pillow - Flip and Rotate Images
- Python Pillow - Resizing an Image
- Python Pillow - Creating a Watermark
- Python Pillow - Adding Filters to an Image
- Python Pillow - Colors on an Image
- Python Pillow - ImageDraw Module
- Python Pillow - Image Sequences
- Python Pillow - Writing Text on Image
- Python Pillow - M L with Numpy
- Python Pillow Useful Resources
- Python Pillow - Quick Guide
- Python Pillow - Useful Resources
- Python Pillow - Discussion
Python Pillow - Writing Text on Image
You can write text on images by passing the location of the text, the text itself and the color of the text. We can pass multiple other parameters to this method.
Example
from PIL import Image, ImageDraw img = Image.open(beach1.jpg') d1 = ImageDraw.Draw(img) d1.text((28, 36), "Hello, TutorialsPoint!", fill=(255, 0, 0)) img.show() img.save("images/image_text.jpg")
Input
Output
If you save the above program as Example.py and execute, it will add the given text on it, and displays it using the standard PNG display utility, as follows −
Selecting the font
There are numerous ways to select the font used for writing on the image. We can either load fonts directly from the system by passing the full path to the function, or we can use the ImageFont to load a TrueType font.
Example
from PIL import Image, ImageDraw, ImageFont img = Image.open('images/logo.jpg') d1 = ImageDraw.Draw(img) myFont = ImageFont.truetype('E:/PythonPillow/Fonts/FreeMono.ttf', 40) d1.text((0, 0), "Sample text", font=myFont, fill =(255, 0, 0)) img.show() img.save("images/image_text.jpg")
Output
Advertisements
To Continue Learning Please Login
Login with Google