How to convert (unicode) text to image?

Dave Angel davea at
Sat Aug 28 11:18:15 CEST 2010

kj wrote:
> Hi!  Does anyone know of an easy way to convert a Unicode string into an image file (either jpg or png)?
> TIA!
> ~k
The question has no meaning as presently worded.

If you have Unicode text that you need to render, so that you end up 
with an image of the text, as printed in some particular font and style, 
you'd probably start with PIL.  Or perhaps one of the gui packages, like 
tkinter, wxpython, etc.

If you have Unicode that was produced by trying to decode some jpeg 
image, then back up and don't do that.  See the recent thread called  
"Writing byte stream as jpeg format to disk".  The OP there had run a 
unicode decode on a byte stream that represented a jpeg file, and then 
tried to encode it again to get the jpeg data.  Bad idea.

If you have Unicode that specifies a file path that refers to a jpeg 
file, then you need to open the file, in "rb" mode, and copy it.

If you have Unicode that gives the name of a person, and you want a 
portrait of that person, you need to call a photographer() function.

The last one was a weak attempt at humor.


More information about the Python-list mailing list