Re: Putting a unicode string on an ImageDraw canvas

Fredrik Lundh <[email protected]>
Newsgroups gmane.comp.python.image
Message-ID <[email protected]>
2011/1/10 Thomas Larsen Wessel <[email protected]>:
> Thanks :)
>
> Here is an example that shows how both draw.text and draw.textsize works, as
> long as a unicode-supported font is supplied. It also shows how to get the
> text size directly from the font object.
>
> import ImageFont, Image, ImageDraw
>
> s = u'\u0623\u0636\u0641'
>
> font = ImageFont.truetype('/host/WINDOWS/Fonts/tahoma.ttf', 12,
> encoding='unic')
> print font.getsize(s) # no problem, works fine
>
> im = Image.new('RGB', (200,200))
> draw = ImageDraw.Draw(im)
> print draw.textsize(s, font=font) #fails

Hmm. That works for me in both 1.1.7 and trunk, and I don't really see
how it can fail for you given that it ends up calling the same method
in both cases:

    def textsize(self, text, font=None):
        if font is None:
            font = self.getfont()
        return font.getsize(text)

What's the exact error?

</F>
_______________________________________________
Image-SIG maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/image-sig
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.