Is there any good python library for generating and rendering text in image format?
Asked Answered
A

5

2

I'm developing a CMS like application where the user should be able to create the menu the way he wants. Ideally, each menu object wouldn't be a text with a background but rather an image of the text. I envision this in either of these 2 ways:

a) By rendering a font in a/several image file/s with every letter and a script that given a word would give me either the sequence of images to string together or a single image file with the combination of all letters. I understand this could be done manually, but I feel there's probably a library to help with this.

b) With some kind of imaging library that would be able to render text with several blending effects such as gradient color, shadows, glow, etc. While I believe this one's a bit harder, maybe there's something that suits this need.

Any tips on any library that does this or anything similar?

Thanks in advance!

Bruno

Apologete answered 2/3, 2011 at 4:32 Comment(0)
B
2

Although nowadays I'd settle to go with web fonts and CSS,a couple of years ago I faced this problem, and put together a small project that would generate text-within a templated image on the file, according to passed URL parameters.

The project is still publicized here: https://bitbucket.org/jsbueno/dynabutton -- it is made to work as a CGI script, but could be easily adapted to work with a more eficient server (I'd recomend some security tunning as well, if you are putting it online). You can also use it to generate all your images with a server side script, and just put the resulting image files online.

(it does use PIL underneath)

Ah yes, it can do shadow, and glow with proper parameters, can use any server-installed font, and will use an image template for providing the background, so you can apply any effect manually. (the included temlates, though, are quite amateurish)

Braley answered 2/3, 2011 at 5:0 Comment(1)
That's a sweet PIL wrapper you made there, exactly what I was looking for. I adapted your code so that it integrates with my app without the need of the CGI server seamlessly. Two thumbs up!Apologete
C
3

We are using Imagemagick.

http://www.imagemagick.org/Usage/text/#attributes

This will render a simple button with text:

convert -background white -fill dodgerblue  -font Candice -strokewidth 2  -stroke blue   -undercolor lightblue  -size 165x70 -gravity center label:Anthony     label_color.gif

Wrapping this into a Python module is straight forward.

Consumable answered 2/3, 2011 at 4:44 Comment(1)
Very neat and powerful. I'm going with jsbueno's answer because it's more straightforward and doesn't need a 3rd party program, but I'll be seriously considering ImageMagick if I need something more elaborated!Apologete
B
2

Although nowadays I'd settle to go with web fonts and CSS,a couple of years ago I faced this problem, and put together a small project that would generate text-within a templated image on the file, according to passed URL parameters.

The project is still publicized here: https://bitbucket.org/jsbueno/dynabutton -- it is made to work as a CGI script, but could be easily adapted to work with a more eficient server (I'd recomend some security tunning as well, if you are putting it online). You can also use it to generate all your images with a server side script, and just put the resulting image files online.

(it does use PIL underneath)

Ah yes, it can do shadow, and glow with proper parameters, can use any server-installed font, and will use an image template for providing the background, so you can apply any effect manually. (the included temlates, though, are quite amateurish)

Braley answered 2/3, 2011 at 5:0 Comment(1)
That's a sweet PIL wrapper you made there, exactly what I was looking for. I adapted your code so that it integrates with my app without the need of the CGI server seamlessly. Two thumbs up!Apologete
Q
0

Check out pycairo, bindings for the cairo rendering package. It can render text as well as graphics.

Quadrireme answered 2/3, 2011 at 4:37 Comment(0)
D
0

Well, with modern CSS techniques, the issue of nonmatching client-side fonts is less of a problem these days. Still there's demand for text-to-image tools.

PIL is often given as the answer to this question, but personally, I would give a good, hard look at pythonmagick as well. Pick the one that works best for you.

Dreg answered 2/3, 2011 at 4:41 Comment(0)
Q
0

Actually the pygtk also has a pango renderer, as well.

Quadrireme answered 2/3, 2011 at 4:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.