Open In App

Wand text() function in Python

Improve
Improve
Like Article
Like
Save
Share
Report

Text can also be added using wand.drawing object. text() function is used to add text in the Drawing object. It takes x and y coordinates and string that we want to write on (x, y) position.

Syntax :

wand.drawing.text(x, y, body)

Parameters :

Parameter Input Type Description
x numbers.Integral the baseline where to start writing text.
y numbers.Integral the left offset where to start writing a text.
body basestring the body string to write.

Example #1: 

Python3




# Import different modules of wand
from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color
import math
  
with Drawing() as draw:
    with Image(width = 200, height = 200, background = Color('lightgreen')) as image:
 
        draw.font = 'wandtests/assets/League_Gothic.otf'
        draw.font_size = 10
        draw.text(image.width / 2, image.height / 2, 'GeeksForGeeks')
        draw(image)
        image.save(filename = "text.png")


Output: Example #2: 

Python3




# Import different modules of wand
from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color
import math
  
with Drawing() as draw:
    with Image(filename = "gog.png") as image:
        draw.font = 'wandtests / assets / League_Gothic.otf'
        draw.font_size = 10
        draw.text(image.width / 2, image.height / 2, 'GeeksForGeeks')
        draw(image)
        image.save(filename = "text.png")


Output :



Last Updated : 16 Mar, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads