How to generate image with a string?

Chris Angelico rosuav at
Thu Dec 20 13:04:58 EST 2018

On Fri, Dec 21, 2018 at 4:50 AM <sntshkmr60 at> wrote:
> More or less I'm trying to replicate in Python. I'll be using Django in the backend. Given all the parameters, I'm not sure how will I be generating the images.
>  * I will be passing width and height of the image and maybe the text and background color.
>  * I also want to center the text vertically and horizontally.
>  * The text size will be increased proportionally to the image being generated.
> Can someone enlighten my path? What libraries can be capable of doing this?

Django is irrelevant here, so what you're trying to do is use Python
code to generate an image containing some text. I don't know the
specifics of that, but I know where I'd go looking, and that's Pillow.
(No, I don't mean that I'd sleep on it, although that IS often a good
idea.) Here's the docs:

The ImageDraw and ImageFont modules look promising here.

I would recommend creating a stand-alone script (outside of Django and
the whole web server system) that generates and saves an image, and
only bring it into your web server once it's working.


More information about the Python-list mailing list