generate labels include qr-code
This commit is contained in:
parent
a11a3f92fb
commit
7e7bf9eef5
2 changed files with 24 additions and 1 deletions
|
@ -8,4 +8,5 @@ python3 -m venv py
|
|||
source py/bin/activate
|
||||
cat generate_labels.py
|
||||
pip install svgwrite
|
||||
pip install svgwrite qrcode[pil]
|
||||
```
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import svgwrite
|
||||
import pyqrcode
|
||||
|
||||
lost_and_found_content = "Found? https://l3d.ch/kontakt"
|
||||
asset_content = "000-00X"
|
||||
|
||||
def create_a4_svg(output_filename):
|
||||
# A4 size in millimeters
|
||||
|
@ -16,7 +20,25 @@ def create_a4_svg(output_filename):
|
|||
for x in range(0,3):
|
||||
for y in range(0,10):
|
||||
print(f"Create Label: X={x}, Y={y}")
|
||||
dwg.add(dwg.rect(insert=(f'{x*70}mm', f'{y*29.7}mm'), size=('70mm', '29.7mm'), fill="red", stroke="none"))
|
||||
# white bg for label
|
||||
dwg.add(dwg.rect(insert=(f'{x*70}mm', f'{y*29.7}mm'), size=('70mm', '29.7mm'), fill="white", stroke="none"))
|
||||
# asset number
|
||||
asset_element = dwg.text(asset_content, insert=(f'{x*70+29.7}mm', f'{y*29.7+10}mm'), font_size="37px", font_family="Lato", fill="black")
|
||||
dwg.add(asset_element)
|
||||
# lost and found
|
||||
lost_and_found_element = dwg.text(lost_and_found_content, insert=(f'{x*70+29.7}mm', f'{y*29.7+15}mm'), font_size="11.3px", font_family="Lato", fill="black")
|
||||
dwg.add(lost_and_found_element)
|
||||
# freitextfeld
|
||||
dwg.add(dwg.rect(insert=(f'{x*70+29.7+0.5}mm', f'{y*29.7+28.2}mm'), size=('38.3mm', '0.2mm'), fill="grey", stroke="none"))
|
||||
|
||||
# create qr-code
|
||||
qr = pyqrcode.create(f'https://i.l3d.ch/a/{asset_content}', error="H")
|
||||
# Save QR code as SVG
|
||||
qr.svg('/tmp/qr.svg', scale=50)
|
||||
# import
|
||||
qr_code_svg = svgwrite.image.Image('/tmp/qr.svg', insert=(f'{x*70}mm', f'{y*29.7}mm'), size=('29.7mm', '29.7mm'))
|
||||
dwg.add(qr_code_svg)
|
||||
|
||||
|
||||
# Save the SVG document
|
||||
dwg.save()
|
||||
|
|
Loading…
Reference in a new issue