# Making a meme!

Workshop Resources

So now that my image looks how I want it to look, I want to add some text. We can do that by utilizing the Pillow ImageDraw module. Let’s import that at the top of our file along with our other import statements.

from PIL import Image
from PIL import ImageFilter
from PIL import ImageDraw


To allow us to add text, we must redraw the same image we used earlier for image manipulation. Let’s do that using the draw() function, which takes in an image object. Once the image is drawn, we can then add text to it by using the text() method to set the text of the image. The text is drawn based on coordinates provided. The function takes in two mandatory parameters: the xy coordinates and the text needed.

For example:

drawnImage = ImageDraw.Draw(greyscaleImage)
drawImage.text((400,1200), "Whatchu doing? Coding?")
greyscaleImage.save("myCatWithText.jpg")


My image now looks like this:

### Hmm, the text seems really small!

You can see that the text in the image created above is in a small, default font. There are other parameters within the text() method you can use. Specifically, we can set the font! To do so, we need to use something called TTF file, which defines a font for us.

To start, you can use the font we use in this workshop: Click to download.

To use this font, you can do the following:

1. Upload the TTF file to repl.it in the same place as your code.
2. In your main.py file, we need to add a few more things to use the font within our meme. First, at the top of the file, add another import line to use the ImageFont library.
from PIL import Image
from PIL import ImageFilter
from PIL import ImageDraw
from PIL import ImageFont

1. Further down in the code, where you are adding the text to the image, you want to add another line in between to set the font, then pass that font into the text() function.

For example:

drawnImage = ImageDraw.Draw(greyscaleImage)
font = ImageFont.truetype(font = 'Roboto-Bold.ttf', size=75)
drawImage.text((400,1200), "Whatchu doing? Coding?", font=font)
greyscaleImage.save("myCatWithText.jpg")


Once I rerun my code, my image now looks like this:

You did it!
Workshop completed!