Scripts to create QR-Code images for storage boxes. Each box has an associated web page describing its content, and the QR-Code serves as a short-link from the physical object to the web page.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

44 lines
1.1 KiB

#! /usr/bin/env python
# -*- coding: utf-8 -*-
# cassette.py
# Copyright 2011 Stefano Costa <steko@unisi.it>
import qrencode
import Image, ImageDraw, ImageFont
def qrlabel(n, txt):
'''Creates a label with QR-Code and short text label.'''
t = 'http://www.gortinabizantina.it/wiki/index.php/Cassetta_%d'
s = 500
n = n
v, s1, im = qrencode.encode_scaled(t % n, s)
box = (0, 0, s, s)
region = im.crop(box)
im2 = im.resize((s*2,s))
im2.paste(255, (0,0,s*2,s))
im2.paste(region, box)
draw = ImageDraw.Draw(im2)
font = ImageFont.truetype('Ubuntu-B.ttf', int(s/2.4))
ts = draw.textsize(txt, font=font)
d1x = int((s * 3 / 2 ) - ( ts[0] / 2 ))
d1y = ( s / 4 ) - ( ts[1] / 2 )
draw.text((d1x, d1y), txt, font=font)
ts = draw.textsize('%d' % n, font=font)
d1x = int((s * 3 / 2 ) - ( ts[0] / 2 ))
d1y = ( s * 3 / 4 ) - ( ts[1] / 2 )
draw.text((d1x, d1y), '%d' % n, font=font)
return im2
if __name__ == '__main__':
for n in range(200):
with open('label%d.png' % n,'wb') as f:
im = qrlabel(n,'GQB')
im.save(f)