How to convert (unicode) text to image?

Dave Angel davea at ieee.org
Sat Aug 28 05:18:15 EDT 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.

DaveA




More information about the Python-list mailing list