![]() ![]() The code we used in this post is not sufficient to draw text boxes as shown in the images above. ![]() Haptik Motivational Quote & Word of the Day in real time, and with data from different API responses. We currently use Pillow to generate images for Jokes, Motivational Quotes, Horoscopes, Word of the Day etc. Voila! It looked great and we decided to use the idea of creating images on-the-go, for other use-cases as well. ![]() And just with a few lines of code, I was able to create an image like this: While at work, I recently developed a feature which demanded the creation of a leaderboard image on-the-fly, with user-specific quiz score data. This generates an output image optimized.png with reduced quality but smaller size. Image.save('optimized.png', optimize=True, quality=20) While you save the image, you can pass optional parameters like optimize and quality to control the size of the output image. x here represents the distance of the text box from the left (x=0) and y represents the distance from the top (y=0). With some fonts, you might have to pass an optional parameter encoding which tells the ImageFont module which encoding to use while opening the font file.Ĭomputer graphics have an inverted coordinate system, the origin(0, 0) that lies at the top-left corner of the image. Let’s take the following background image and initialize it with the following code:īelow is what you get after executing the above code:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |