|
@@ -19,7 +19,7 @@ class Label():
|
|
def create(self):
|
|
def create(self):
|
|
self.img = Image.new('RGB', (self.pixels_x, self.pixels_y), color=self.bg_color)
|
|
self.img = Image.new('RGB', (self.pixels_x, self.pixels_y), color=self.bg_color)
|
|
|
|
|
|
- def draw_text(self, text : str, pos_x, pos_y, color=(0,0,0), size=10, font_file=None, centered=False, scale_to_fit=False):
|
|
|
|
|
|
+ def draw_text(self, text : str, pos_x, pos_y, color=(0,0,0), size=10, font_file=None, centered_x=False, centered_y=False, scale_to_fit=False):
|
|
d = ImageDraw.Draw(self.img)
|
|
d = ImageDraw.Draw(self.img)
|
|
if font_file is None or font_file == 'regular':
|
|
if font_file is None or font_file == 'regular':
|
|
font_file = self.regular_font_fname
|
|
font_file = self.regular_font_fname
|
|
@@ -34,11 +34,14 @@ class Label():
|
|
fnt = ImageFont.truetype(font_file, size)
|
|
fnt = ImageFont.truetype(font_file, size)
|
|
w, h = d.textsize(text, font=fnt)
|
|
w, h = d.textsize(text, font=fnt)
|
|
|
|
|
|
- if centered:
|
|
|
|
|
|
+ if centered_x:
|
|
pos_x = orig_pos_x - w / 2
|
|
pos_x = orig_pos_x - w / 2
|
|
- pos_y = orig_pos_y - h / 2
|
|
|
|
else:
|
|
else:
|
|
pos_x = orig_pos_x
|
|
pos_x = orig_pos_x
|
|
|
|
+
|
|
|
|
+ if centered_y:
|
|
|
|
+ pos_y = orig_pos_y - h / 2
|
|
|
|
+ else:
|
|
pos_y = orig_pos_y
|
|
pos_y = orig_pos_y
|
|
|
|
|
|
if not scale_to_fit:
|
|
if not scale_to_fit:
|
|
@@ -70,6 +73,9 @@ class Label():
|
|
self.img.save(fname)
|
|
self.img.save(fname)
|
|
|
|
|
|
return fname
|
|
return fname
|
|
|
|
+
|
|
|
|
+ def get_pillow_image(self):
|
|
|
|
+ return self.img
|
|
|
|
|
|
|
|
|
|
class MiceToiletLabel(Label):
|
|
class MiceToiletLabel(Label):
|
|
@@ -82,8 +88,8 @@ class MiceToiletLabel(Label):
|
|
self.create()
|
|
self.create()
|
|
|
|
|
|
def put_text(self, heading, line1=None, line2=None):
|
|
def put_text(self, heading, line1=None, line2=None):
|
|
- self.draw_text(heading, self.pixels_x/2, 20, size=25, font_file='bold', centered=True, scale_to_fit=True)
|
|
|
|
|
|
+ self.draw_text(heading, self.pixels_x/2, 20, size=25, font_file='bold', centered_x=True, centered_y=True, scale_to_fit=True)
|
|
if line1:
|
|
if line1:
|
|
- self.draw_text(line1, self.pixels_x/2, 55, size=20, centered=True, scale_to_fit=True)
|
|
|
|
|
|
+ self.draw_text(line1, self.pixels_x/2, 55, size=20, centered_x=True, centered_y=True, scale_to_fit=True)
|
|
if line2:
|
|
if line2:
|
|
- self.draw_text(line2, self.pixels_x/2, 85, size=20, centered=True, scale_to_fit=True)
|
|
|
|
|
|
+ self.draw_text(line2, self.pixels_x/2, 85, size=20, centered_x=True, centered_y=True, scale_to_fit=True)
|