From: alejandro on
Can please someone run this little script that should output characters like
���� in an image.
If it does it correctly can you tell me what OS, python version & PIL
version you have?
Or better if someone can tell me why this is not working properly on my PC?
(Win XP, PIL 1.1.6., Python 2.6...)
I don't recive any error it's just that the characters outputed in the image
are not characters... more like symbols...

# encoding:utf-8

from PIL import Image
import ImageDraw
import ImageFont


img = Image.new("RGBA",(250,40))

#----------------------------------- making the image transparent
pixdata = img.load()

for y in xrange(img.size[1]):
for x in xrange(img.size[0]):
if pixdata[x, y] == (255, 255, 255, 255):
pixdata[x, y] = (255, 255, 255, 0)

#--------------------------------- drawing text
draw = ImageDraw.Draw(img)
arial = ImageFont.truetype("arial.ttf",32) # needs path to font, my font
was in the same folder as the script
string = "proba test ����"
draw.text((20,8),string ,font=arial, fill="red")

# write
img.save("img2.png", "PNG")


From: Peter Otten on
alejandro wrote:

> Can please someone run this little script that should output characters
> like ����� in an image.
> If it does it correctly can you tell me what OS, python version & PIL
> version you have?
> Or better if someone can tell me why this is not working properly on my
> PC? (Win XP, PIL 1.1.6., Python 2.6...)
> I don't recive any error it's just that the characters outputed in the
> image are not characters... more like symbols...
>
> # encoding:utf-8
>
> from PIL import Image
> import ImageDraw
> import ImageFont

# the last tuple is the background color
img = Image.new("RGBA",(300, 50), (0, 0, 0, 0))

> draw = ImageDraw.Draw(img)
> arial = ImageFont.truetype("arial.ttf",32) # needs path to font, my font
> was in the same folder as the script

# 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")

> # write
> img.save("img2.png", "PNG")

Peter

From: alejandro on

> # 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

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: Peter Otten on
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
>
> 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

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
From: alejandro on

>
> 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 was the output of my script on your computer?