We will do many things in this step. For this step, we have to import a couple of modules from the Pillow library that we have installed earlier.
from PIL import Image, ImageFont, ImageDraw
The Background Image
Cool! Now let’s go ahead and import the image we picked. ImageDraw method converts the image into an editable format.
bg_image = Image.open("image_leaves.jpg")quote_image = ImageDraw.Draw(bg_image)
Now, let’s define the text font that we want to use. I am going with Roboto font with font size of 52. I’ve downloaded this font from Google Fonts website. We are also assigning the quote and author values into new variables.
quote_font = ImageFont.truetype('Roboto_Slab/RobotoSlab-VariableFont_wght.ttf', 52)quote_text = result['quote']
Text on Image
Here comes the tricky part, which is fitting the quoted text into the image. Since the full quote is in one line, we need to split it into different lines to work well. I tried to do this splitting without using any library, and here is what I did.
The first thing to do is splitting the complete quote by commas. But as you can see below, there is a line that is still so long.
Continue reading: https://towardsdatascience.com/python-for-art-design-personalized-quote-images-using-python-44ef4d8876d8?source=rss—-7f60cf5620c9—4