dont use temp variables to compute ox.image.ZONE_INDEX

This commit is contained in:
j 2016-06-08 12:35:33 +02:00
parent 51da4fd809
commit 170af83272

View file

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