From 440c7ad49b94f4230b4443b340e796ae82f8f206 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Thu, 20 Nov 2014 10:50:09 +0000 Subject: [PATCH] add font offset to getTextSize if PIL is > 2.1 < 2.6.1 --- ox/image.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ox/image.py b/ox/image.py index 4a1b57b..5d609d0 100644 --- a/ox/image.py +++ b/ox/image.py @@ -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