PIL truncates upper letters

I spent a lot of time building my first web application using Python, and I use pil to generate images. After a lot of reading, I managed to implement the correct text alignment, wrapping, creating files with many extensions, etc.

However, all the text generated by the PIL is trimmed at the top. Here is a sample.

Example of PIL-generated image with text cut off at the top

It should say ŻÓĆjygpqin different fonts (font names are on the left).

I found a few posts here: fonts that trim PIL , but I would like to avoid using another module (aggdraw); since I already thought a lot about PIL, I would like to do this.

, - . PIL, . [ OTF BDF PIL].

Ubuntu. ?

+5
3

, _imagingft.c . PIL FreeType , PIL, -, . , getsize ( ). : http://pastebin.com/jP2iLkDN (, ).

, , :

enter image description here   enter image description here

, . OSX:

enter image description here   enter image description here

Ubuntu:

enter image description here   enter image description here

:

# -*- encoding: utf8 -*-
import sys
import Image, ImageDraw, ImageFont

im = Image.new("RGBA", (1000, 1000), 'white')
draw = ImageDraw.Draw(im)

start_y = 7
text = u'\u00d1\u00d3yŻ\u00d4Ćgp\u010c\u0137'
for i in xrange(28, 46, 2):
    font = ImageFont.truetype('Junicode-Bold.ttf', i)
    width, height = font.getsize(text)
    draw.rectangle((0, start_y, width, height + start_y), outline='blue')
    draw.text((0, start_y), text, font=font, fill='black')
    start_y += height + 7

im.crop((0, 0, width + 1, start_y + 2)).save(sys.argv[1])

, PIL, .

+4

, , , .

+1

.

, PIL Pillow . (, 'y's). . , , . , text(). , "font.size * number_chars" ", ", (_imagingft.c). , , .

:

  • . im.text(xy, my_text + ' ',...)
  • (font.getsize()), - , font.getsize() font.getsize() .
  • , AggDraw pyvips.

PIL, PIL , Python . , .

0

All Articles