Python PIL | ImageDraw.Draw.multiline_text ()

Python Methods and Functions

ImageDraw.Draw.multiline_text() Draws a line at the given position.

Syntax:
ImageDraw.Draw.multiline_text (xy, text, fill = None, font = None, anchor = None, spacing = 0, align = ”left”)

Parameters:

xy - Top left corner of the text.
text - Text to be drawn.
fill - Color to use for the text.
font - An ImageFont instance.
spacing - The number of pixels between lines.
align - If the text is passed on to multiline_text (), “left”, “center” or “right”.

Return Type: -
returns an image with text.

Image used:

Code: ImageDraw.Draw.m example ultiline_text ()

 
# Import Image and ImageFont, ImageDraw module from the PIL package

from PIL import Image, ImageFont, ImageDraw 

 
# create image object

image = Image. open (r 'C: UsersSystem-PcDesktopROSE.jpg '

  

draw = ImageDraw.Draw (image) 

  
# specified font size

font = ImageFont.truetype (r 'C: UsersSystem-PcDesktoparial.ttf' , 15

spacing = 50

text = u & quot; & quot; & quot; /

ALWAYS BE HAPPY
(BEST MEDICINE LAUGHS) & quot; & quot; & quot;

 
# font size

draw.text (( 6 , 8 ), text, fill = " red " , font = font, 

spacing = spacing, align = "right"

 
image.show () 

Exit:

Another example: here we change the parameter.

Image used:

Code : example ImageDraw.Draw.multiline_text ()

 

 
# Import Image and ImageFont, ImageDraw module from PIL

from PIL import Image, ImageFont, ImageDraw 

 
# create an image object

image = Image. open (r 'C: UsersSystem- PcDesktopflower.jpg'

 

draw = ImageDraw.Draw (image) 

 
# specified font size

font = ImageFont.truetype (r 'C: UsersSystem-PcDesktoparial.ttf' , 15

spacing = 50

text = u & quot; & quot; & quot; /

ALWAYS BE HAPPY
(BEST MEDICINE LAUGHS) & quot; & quot; & quot;

 
# font size

draw.text (( 6 , 8 ), text, fill = " black "

font = font, spacing = spacing, align = "right"

 
image.show () 

Exit: