Re: TrueType/OpenType rendering bug in PIL 1.1.7?

Edward Cannon <[email protected]>
Newsgroups gmane.comp.python.image
Message-ID <[email protected]>
I ran you code on my machine (win 7 Python 2.6.4, PIL 1.1.6) and after
changing the font names (they are different on my system) I got
similar problems, but not the same. I did notice that your image has
"fish & fhips" whereas mine says "fish & chips" Something seems to be
slightly off.
Hope that helps.
Edward Cannon

On Wed, Oct 6, 2010 at 3:01 PM, Anders Sandvig <[email protected]> wrote:
> I ran the following code in Python 2.6.1 with PIL 1.1.7 on Mac OS X 10.6.4:
>
> #!/usr/bin/python
> from PIL import Image, ImageDraw, ImageFont
>
> image = Image.new("RGB", (800, 600), (127, 127, 127))
> drawer = ImageDraw.Draw(image)
>
> fonts = ("Verdana Bold.ttf", "Verdana Bold Italic.ttf",
>         "Arial Bold.ttf", "Arial Bold Italic.ttf",
>         "AGaramondPro-Bold.otf", "AGaramondPro-BoldItalic.otf",
>         "Zapfino.ttf")
>
> x = 100
> y = 20
> for name in fonts:
>    font = ImageFont.truetype("/Library/Fonts/" + name, 32)
>    text = "fish & chips (%s)" % (name)
>    (w, h) = font.getsize(text)
>    drawer.rectangle([x, y, x + w, y + h], fill=(0, 170, 0))
>    drawer.text((x, y), text, font=font, fill=(255, 255, 255))
>    y += h + 20
>
> image.save("fontbug.png", "PNG")
>
> The result can be found here:
> http://files.looplabel.net/pil/fontbug.png
>
> As you can see, the last two fonts are rendered outside the expected
> box (as returned by ImageFont.getsize()).
>
> It's also odd how the ending first 'f' of the Garamond Bold Italic
> rendering is clipped to the left (compared to the second 'f' in the
> sentence), as is the ending parenthesis of the Arial Bold Italic
> rendering (clipped on the right, seemingly on the edge of the box
> calculated by ImageFont.getsize()).
>
> I am not sure which version of FreeType2 PIL is compiled against (PIL
> was compiled from source), but it's the version installed in
> /usr/X11/lib and /usr/X11/include on my system (i.e. whatever came
> with Mac OS X, I haven't installed any custom versions).
>
> I may be wrong, but as a naive user, I would expect ImageDraw.text()
> to draw inside the same area as returned by ImageFont.getsize(). I've
> also tried substituting ImageFont.getsize() for ImageDraw.textsize(),
> but the results are the same.
>
> So anyone have any clue on what's causing this and/or how to fix it?
>
> ... or maybe I'm just using the functions the wrong way?
>
> BTW: I get the same (unexpected) result when running on a Windows
> XP/Cygwin system (same versions of Python and PIL), compiled against
> whatever is the latest version of FreeType2 for Cygwin -- I can check
> when I access the Windows machine tomorrow.
>
>
> Regards,
>
> Anders
> _______________________________________________
> Image-SIG maillist  -  [email protected]
> http://mail.python.org/mailman/listinfo/image-sig
>
_______________________________________________
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.