fix landscape
[ql570.git] / python / label.py
1 from PIL import Image, ImageFont, ImageDraw
2
3 class label:
4         def __init__(self, length, width=336, landscape=False):
5                 assert(width == 336 or width == 720)
6                 self.landscape = landscape
7                 self.fontfile = '/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf'
8
9                 self.im = Image.new("1", (width, length), "white")
10                 if self.landscape:
11                         self.im = self.im.rotate(90)
12
13         def set_font(self, fontfile):
14                 self.fontfile = fontfile
15
16         def set_fontsize(self, size):
17                 self.font = ImageFont.truetype(self.fontfile, size)
18
19         def text(self, pos, text):
20                 draw = ImageDraw.Draw(self.im)
21                 draw.text(pos, text, font=self.font)
22
23         def save(self, outfile):
24                 if not self.landscape:
25                         self.im = self.im.rotate(90)
26                 self.im.save(outfile, "PNG")