aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAsbjørn Sloth Tønnesen <asbjorn@asbjorn.biz>2012-03-07 16:55:31 +0000
committerAsbjørn Sloth Tønnesen <asbjorn@asbjorn.biz>2012-03-07 16:55:31 +0000
commit7a198c587000c0e3d405707c670798e5eb376f3e (patch)
tree35fd525a1033ee24afb7c8cddf48e0701a4102e4
parentf923f9b006081cd14346f811e9cacb9ab5966a38 (diff)
downloadql570-7a198c587000c0e3d405707c670798e5eb376f3e.tar.gz
ql570-7a198c587000c0e3d405707c670798e5eb376f3e.tar.xz
ql570-7a198c587000c0e3d405707c670798e5eb376f3e.zip
simple label coding in python
-rw-r--r--python/dveth_29mm.py8
-rw-r--r--python/dveth_62mm.py8
-rw-r--r--python/label.py26
3 files changed, 42 insertions, 0 deletions
diff --git a/python/dveth_29mm.py b/python/dveth_29mm.py
new file mode 100644
index 0000000..cb84ca7
--- /dev/null
+++ b/python/dveth_29mm.py
@@ -0,0 +1,8 @@
+from label import label
+
+l = label(1500)
+l.set_font('/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf');
+l.set_fontsize(70)
+for i in range(0,15):
+ l.text((7, 10+i*100), "dveth%02d" % (i))
+l.save('dveth_29mm.png')
diff --git a/python/dveth_62mm.py b/python/dveth_62mm.py
new file mode 100644
index 0000000..548ba28
--- /dev/null
+++ b/python/dveth_62mm.py
@@ -0,0 +1,8 @@
+from label import label
+
+l = label(2425, width=720)
+l.set_font('/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf');
+l.set_fontsize(150)
+for i in range(0,15):
+ l.text((7, 10+i*160), "dveth%02d" % (i))
+l.save('dveth_62mm.png')
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")