Python Pillow Tutorial
Selected Reading
- Python Pillow - Discussion
- Python Pillow - Useful Resources
- Python Pillow - Quick Guide
- Python Pillow - M L with Numpy
- Python Pillow - Writing Text on Image
- Python Pillow - Image Sequences
- Python Pillow - ImageDraw Module
- Python Pillow - Colors on an Image
- Python Pillow - Adding Filters to an Image
- Python Pillow - Creating a Watermark
- Python Pillow - Resizing an Image
- Python Pillow - Flip and Rotate Images
- Python Pillow - Cropping an Image
- Python Pillow - Blur an Image
- Python Pillow - Merging Images
- Python Pillow - Creating Thumbnails
- Python Pillow - Working with Images
- Python Pillow - Using Image Module
- Python Pillow - Environment Setup
- Python Pillow - Overview
- Python Pillow - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Python Pillow - Writing Text on Image
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 utipty, 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")