From cca251bc3258907865eb5a34a697ca51c683ad85 Mon Sep 17 00:00:00 2001 From: rolux Date: Thu, 6 Jun 2013 17:29:52 +0200 Subject: [PATCH] ox.image: add getTextSize method --- ox/image.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ox/image.py b/ox/image.py index 9910c22..96a228f 100644 --- a/ox/image.py +++ b/ox/image.py @@ -132,6 +132,11 @@ def getRGB(hsl): rgb[i] = v1 return tuple(map(lambda x: int(x * 255), rgb)) +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) + def wrapText(text, max_width, max_lines, font_file, font_size): # wraps text to max_width and max_lines def get_width(string):