pgmagick – Add text in images

In this article we will see how to add text to images using pgmagick library in Python. We can do this by using annotate() function. Sometimes, we need to add text to images like for its copyright or name of the organization the image is associated with.

In this article we will create an image with a green background text ‘GeeksforGeeks’ on it and will manipulate text on it.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing library
from pgmagick.api import Image
  
# using image function
img = Image((300, 300), 'green')
img.annotate('GeeksforGeeks')
img.write('GeeksforGeeks.jpg')

chevron_right


Output :

Now, we will rotate the text to 45 degrees.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing library
from pgmagick.api import Image
  
img = Image((300, 300), 'green')
  
# annotate function 
img.annotate('GeeksforGeeks', angle = 45)
img.write('geeksforgeeks.png')

chevron_right




Now we will change font as well as size of text.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing library
from pgmagick.api import Image
  
img = Image((300, 200), 'green')
img.font("/usr/share/fonts/truetype/ttf-japanese-gothic.ttf")
img.font_pointsize(26)
  
# annotate function 
img.annotate('GeeksforGeeks')
img.write('GeeksforGeeks.png')

chevron_right


Output :

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up

Hi there I am a student of CGC COE, Landran in CSE department and have a great interest in programming

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.