X-Git-Url: http://git.asbjorn.biz/?p=ql570.git;a=blobdiff_plain;f=python%2Flabel.py;fp=python%2Flabel.py;h=41618bb7c9d8e6c19730f0eb3e541749f2804a2c;hp=0000000000000000000000000000000000000000;hb=7a198c587000c0e3d405707c670798e5eb376f3e;hpb=f923f9b006081cd14346f811e9cacb9ab5966a38 diff --git a/python/label.py b/python/label.py new file mode 100644 index 0000000..41618bb --- /dev/null +++ b/python/label.py @@ -0,0 +1,26 @@ +from PIL import Image, ImageFont, ImageDraw + +class label: + def __init__(self, length, width=336, landscape=False): + assert(width == 336 or width == 720) + self.landscape = False + self.fontfile = '/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf' + + self.im = Image.new("1", (width, length), "white") + if self.landscape: + self.im.rotate(90) + + def set_font(self, fontfile): + self.fontfile = fontfile + + def set_fontsize(self, size): + self.font = ImageFont.truetype(self.fontfile, size) + + def text(self, pos, text): + draw = ImageDraw.Draw(self.im) + draw.text(pos, text, font=self.font) + + def save(self, outfile): + if self.landscape: + self.im.rotate(90) + self.im.save(outfile, "PNG")