bigger name in printed labels

This commit is contained in:
Davide Alberani 2015-05-16 20:07:47 +02:00
parent cde0700a64
commit 82fb9789b1

View file

@ -14,12 +14,12 @@ import cups
import tempfile
from PIL import Image, ImageFont, ImageDraw
KEEP_IMG = False
KEEP_IMG = True
LABEL_WIDTH = 13488
LABEL_HEIGHT = 3744
FONT_TEXT = 'Ubuntu-C.ttf'
#FONT_TEXT = 'CONCIBB_.TTF'
FONT_TEXT = 'CONCIBB_.TTF'
FONT_TEXT_ENCODING = 'latin-1'
FONT_BARCODE = 'free3of9.ttf'
@ -36,14 +36,15 @@ def build_label(w, h, barcode_text, line1, line2, font_text=FONT_TEXT, font_barc
line1 = unicode(line1, 'utf-8').encode(FONT_TEXT_ENCODING, 'ignore')
line2 = unicode(line2, 'utf-8').encode(FONT_TEXT_ENCODING, 'ignore')
fontbar = ImageFont.truetype(_get_resource(font_barcode), 2000)
fontnorm = ImageFont.truetype(_get_resource(font_text), 840)
fontname = ImageFont.truetype(_get_resource(font_text), 1100)
fontjob = ImageFont.truetype(_get_resource(font_text), 780)
image = Image.new('RGB', (w, h), (255, 255, 255))
draw = ImageDraw.Draw(image)
wbar, hbar = draw.textsize(barcode_text, font=fontbar)
wnorm1, hnorm1 = draw.textsize(line1, font=fontnorm)
wnorm2, hnorm2 = draw.textsize(line2, font=fontnorm)
draw.text(((w-wnorm1)/2, -1200+(h-hnorm1)/2), line1, (0, 0, 0), font=fontnorm)
draw.text(((w-wnorm2)/2, -450+(h-hnorm2)/2), line2, (0, 0, 0), font=fontnorm)
wnorm1, hnorm1 = draw.textsize(line1, font=fontname)
wnorm2, hnorm2 = draw.textsize(line2, font=fontjob)
draw.text(((w-wnorm1)/2, -1300+(h-hnorm1)/2), line1, (0, 0, 0), font=fontname)
draw.text(((w-wnorm2)/2, -480+(h-hnorm2)/2), line2, (0, 0, 0), font=fontjob)
draw.text(((w-wbar)/2, 850+(h-hbar)/2), barcode_text, (0, 0, 0), font=fontbar)
if not KEEP_IMG:
tmpfile = tempfile.NamedTemporaryFile(prefix='eventman_print_label_', suffix='.png')