Saturday, October 18, 2025
HomeLanguagesPython PIL | ImageDraw.Draw.multiline_textsize()

Python PIL | ImageDraw.Draw.multiline_textsize()


PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. The ImageDraw module provide simple 2D graphics for Image objects. You can use this module to create new images, annotate or retouch existing images, and to generate graphics on the fly for web use.

ImageDraw.Draw.multiline_textsize() Return the size of the given string, in pixels.

Syntax:
ImageDraw.Draw.multiline_textsize(text, font=None, spacing=0)

Parameters:
text – Text to be measured.
font – An ImageFont instance.
spacing – The number of pixels between lines.

Return Type:
returns an image with text.

Image Used:

Code : Using ImageDraw.Draw.multiline_textsize




   
  
# Importing Image and ImageFont, ImageDraw module from PIL package 
from PIL import Image, ImageFont, ImageDraw 
      
# creating a image object 
image = Image.open(r'C:\Users\System-Pc\Desktop\rose.jpg') 
  
draw = ImageDraw.Draw(image) 
  
#specified font size
font = ImageFont.truetype(r'C:\Users\System-Pc\Desktop\arial.ttf',30)
  
text =u"""\
ALWAYS BE HAPPY
(LAUGHING IS THE \n BEST MEDICINE)"""
  
# drawing text size
draw.text((20,18), text,font = None,spacing=0) 
  
image.show() 


Output:

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS