add font offset to getTextSize if PIL is > 2.1 < 2.6.1
This commit is contained in:
parent
645cc0ff04
commit
440c7ad49b
1 changed files with 7 additions and 1 deletions
|
@ -141,7 +141,13 @@ def getRGB(hsl):
|
|||
def getTextSize(image, text, font_file, font_size):
|
||||
draw = ImageDraw.Draw(image)
|
||||
font = ImageFont.truetype(font_file, font_size, encoding='unic')
|
||||
return draw.textsize(text, font=font)
|
||||
size = draw.textsize(text, font=font)
|
||||
version = getattr(Image, 'PILLOW_VERSION', None)
|
||||
if version and version > '2.1.0' and version < '2.6.1':
|
||||
offset = font.getoffset(text)
|
||||
else:
|
||||
offset = (0, 0)
|
||||
return (size[0] + offset[0], size[1] + offset[1])
|
||||
|
||||
def wrapText(text, max_width, max_lines, font_file, font_size):
|
||||
# wraps text to max_width and max_lines
|
||||
|
|
Loading…
Reference in a new issue