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')