From: Peter Otten on 6 Aug 2010 11:44 alejandro wrote: >> Make sure that >> >> # encoding:utf-8 >> >> is the first line of your script, details and fineprint here: >> >> http://www.python.org/dev/peps/pep-0263/ >> >> Peter > > Tryed that... What happened? > What was the output of my script on your computer? $ python -V Python 2.6.4 $ python -c "import Image; print Image.VERSION" 1.1.6 $ cat draw_text.py # encoding:utf-8 from PIL import Image import ImageDraw import ImageFont img = Image.new("RGBA",(300, 50), (0, 0, 0, 0)) draw = ImageDraw.Draw(img) FONT = "/usr/share/fonts/truetype/msttcorefonts/arial.ttf" arial = ImageFont.truetype(FONT, 32) text = u"proba test ¾æèð¹" print repr(text) draw.text((20,8), text, font=arial, fill="red") img.save("tmp.png") $ python draw_text.py u'proba test \xbe\xe6\xe8\xf0\xb9' The image looks as expected. Peter
From: Thomas Jollans on 6 Aug 2010 12:55 On 08/06/2010 04:37 PM, alejandro wrote: > >> # the last tuple is the background color >> img = Image.new("RGBA",(300, 50), (0, 0, 0, 0)) > Thank you for this.... > >> # I think that the PIL can cope with unicode, so add a u-prefix here: >> text = u"proba test ����" >> draw.text((20,8), text ,font=arial, fill="red") > > Nope i gives: > SyntaxError: (unicode error) 'utf8' codec can't decode byte 0x9e in position > 0: unexpected code byte Is the file, which you claim is UTF-8 encoded, actually UTF-8 encoded? If you're not sure, explicitly tell your text editor to save the file as UTF-8, and then try again. > > and without the encoding : > SyntaxError: Non-ASCII character '\x9e' in file C:\Documents and > Settings\Perc\My Documents\NetBeansProjects\venus_header\src\venus_header.py > on line 16, but no encoding declared; see > http://www.python.org/peps/pep-0263.html for details > > >
From: alejandro on 7 Aug 2010 05:09 > > Is the file, which you claim is UTF-8 encoded, actually UTF-8 encoded? > If you're not sure, explicitly tell your text editor to save the file as > UTF-8, and then try again. I feel like an idiot... haven't used Python for some time... my editor was set for utf-8 on PHP projects and other... but somehow i forgot to set for py files too... thanks both of you!
First
|
Prev
|
Pages: 1 2 Prev: Python Portability Next: How to read large amounts of output via popen |