Optimize label cration
This commit is contained in:
parent
7e7bf9eef5
commit
00d54045c1
1 changed files with 6 additions and 5 deletions
|
@ -4,7 +4,7 @@ import svgwrite
|
||||||
import pyqrcode
|
import pyqrcode
|
||||||
|
|
||||||
lost_and_found_content = "Found? https://l3d.ch/kontakt"
|
lost_and_found_content = "Found? https://l3d.ch/kontakt"
|
||||||
asset_content = "000-00X"
|
asset_content_prefix = "000-"
|
||||||
|
|
||||||
def create_a4_svg(output_filename):
|
def create_a4_svg(output_filename):
|
||||||
# A4 size in millimeters
|
# A4 size in millimeters
|
||||||
|
@ -17,13 +17,14 @@ def create_a4_svg(output_filename):
|
||||||
# Add your content or elements to the SVG here
|
# Add your content or elements to the SVG here
|
||||||
# For example, you can add a rectangle as a placeholder
|
# For example, you can add a rectangle as a placeholder
|
||||||
# dwg.add(dwg.rect(insert=(10, 10), size=(a4_width_svg - 20, a4_height_svg - 20), fill="white", stroke="black"))
|
# dwg.add(dwg.rect(insert=(10, 10), size=(a4_width_svg - 20, a4_height_svg - 20), fill="white", stroke="black"))
|
||||||
|
asset_content_suffix=0
|
||||||
for x in range(0,3):
|
for x in range(0,3):
|
||||||
for y in range(0,10):
|
for y in range(0,10):
|
||||||
print(f"Create Label: X={x}, Y={y}")
|
print(f"Create Label: X={x}, Y={y} - {asset_content_prefix}{asset_content_suffix:03}")
|
||||||
# white bg for label
|
# 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"))
|
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 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")
|
asset_element = dwg.text(str(f"{asset_content_prefix}{asset_content_suffix:03}"), 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)
|
dwg.add(asset_element)
|
||||||
# lost and found
|
# 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")
|
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")
|
||||||
|
@ -32,13 +33,13 @@ def create_a4_svg(output_filename):
|
||||||
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"))
|
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
|
# create qr-code
|
||||||
qr = pyqrcode.create(f'https://i.l3d.ch/a/{asset_content}', error="H")
|
qr = pyqrcode.create(f'https://i.l3d.ch/a/{asset_content_prefix}{asset_content_suffix:03}', error="H")
|
||||||
# Save QR code as SVG
|
# Save QR code as SVG
|
||||||
qr.svg('/tmp/qr.svg', scale=50)
|
qr.svg('/tmp/qr.svg', scale=50)
|
||||||
# import
|
# 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'))
|
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)
|
dwg.add(qr_code_svg)
|
||||||
|
asset_content_suffix+= 1
|
||||||
|
|
||||||
# Save the SVG document
|
# Save the SVG document
|
||||||
dwg.save()
|
dwg.save()
|
||||||
|
|
Loading…
Reference in a new issue