From 170af832721f169fa1ffb6304b2061969c85fef5 Mon Sep 17 00:00:00 2001 From: j Date: Wed, 8 Jun 2016 12:35:33 +0200 Subject: [PATCH] dont use temp variables to compute ox.image.ZONE_INDEX --- ox/image.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ox/image.py b/ox/image.py index e7c7541..0fad5eb 100644 --- a/ox/image.py +++ b/ox/image.py @@ -14,12 +14,13 @@ except: import ImageFont -ZONE_INDEX = [] -for pixel_index in range(64): - x, y = pixel_index % 8, int(pixel_index / 8) - ZONE_INDEX.append(int(x / 2) + int(y / 4) * 4) -del x -del y +ZONE_INDEX = [ + (int(x / 2) + int(y / 4) * 4) + for x, y in [ + (pixel_index % 8, int(pixel_index / 8)) + for pixel_index in range(64) + ] +] def drawText(image, position, text, font_file, font_size, color): draw = ImageDraw.Draw(image) @@ -165,8 +166,10 @@ def wrapText(text, max_width, max_lines, font_file, font_size): if width <= max_width and width > min_width: min_width = width return min_width + def get_width(string): return draw.textsize(string, font=font)[0] + image = Image.new('RGB', (1, 1)) draw = ImageDraw.Draw(image) font = ImageFont.truetype(font_file, font_size, encoding='unic')