diff --git a/ox/image.py b/ox/image.py index 535b8dd..dc3e334 100644 --- a/ox/image.py +++ b/ox/image.py @@ -22,11 +22,17 @@ ZONE_INDEX = [ ] ] + +def textsize(draw, text, font): + left, top, right, bottom = draw.textbbox((0, 0), text, font=font) + return (right, bottom) + + def drawText(image, position, text, font_file, font_size, color): draw = ImageDraw.Draw(image) font = ImageFont.truetype(font_file, font_size, encoding='unic') draw.text(position, text, fill=color, font=font) - size = draw.textsize(text, font=font) + size = textsize(draw, text, font) version = getattr(Image, 'PILLOW_VERSION', None) if version and version > '2.1.0' and version < '2.6.1': offset = font.getoffset(text) @@ -148,7 +154,7 @@ def getRGB(hsl): def getTextSize(image, text, font_file, font_size): draw = ImageDraw.Draw(image) font = ImageFont.truetype(font_file, font_size, encoding='unic') - size = draw.textsize(text, font=font) + size = textsize(draw, text, font) version = getattr(Image, 'PILLOW_VERSION', None) if version and version > '2.1.0' and version < '2.6.1': offset = font.getoffset(text) @@ -168,7 +174,7 @@ def wrapText(text, max_width, max_lines, font_file, font_size): return min_width def get_width(string): - return draw.textsize(string, font=font)[0] + return textsize(draw, text, font)[0] image = Image.new('RGB', (1, 1)) draw = ImageDraw.Draw(image)