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 import ImageFont
ZONE_INDEX = [] ZONE_INDEX = [
for pixel_index in range(64): (int(x / 2) + int(y / 4) * 4)
x, y = pixel_index % 8, int(pixel_index / 8) for x, y in [
ZONE_INDEX.append(int(x / 2) + int(y / 4) * 4) (pixel_index % 8, int(pixel_index / 8))
del x for pixel_index in range(64)
del y ]
]
def drawText(image, position, text, font_file, font_size, color): def drawText(image, position, text, font_file, font_size, color):
draw = ImageDraw.Draw(image) 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: if width <= max_width and width > min_width:
min_width = width min_width = width
return min_width return min_width
def get_width(string): def get_width(string):
return draw.textsize(string, font=font)[0] return draw.textsize(string, font=font)[0]
image = Image.new('RGB', (1, 1)) image = Image.new('RGB', (1, 1))
draw = ImageDraw.Draw(image) draw = ImageDraw.Draw(image)
font = ImageFont.truetype(font_file, font_size, encoding='unic') font = ImageFont.truetype(font_file, font_size, encoding='unic')