Files

41 lines
1.2 KiB
Python
Raw Permalink Normal View History

2025-04-25 15:04:33 -06:00
from PIL import Image, ImageEnhance, ImageFont, ImageDraw
import os
import textwrap
import qrcode
import urllib.parse
location = os.path.dirname(os.path.realpath(__file__))
def print_consumable_label(item):
im = Image.open(location + '/label.png')
width, height = im.size
draw = ImageDraw.Draw(im)
2025-04-27 16:30:02 -06:00
#logging.info('Printing consumable label item: %s', item)
2025-04-25 15:04:33 -06:00
encodeded = urllib.parse.quote(item)
2025-04-27 16:30:02 -06:00
url = 'https://my.protospace.ca/out-of-stock?item=' + encodeded
2025-04-25 15:04:33 -06:00
2025-04-27 16:30:02 -06:00
qr = qrcode.make(url, version=6, box_size=9)
im.paste(qr, (840, 325))
2025-04-25 15:04:33 -06:00
item_size = 150
w = 9999
while w > 1200:
item_size -= 5
2025-04-27 16:30:02 -06:00
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', item_size)
2025-04-25 15:04:33 -06:00
w, h = draw.textsize(item, font=font)
2025-04-27 16:30:02 -06:00
x, y = (width - w) / 2, ((height - h) / 2) - 140
2025-04-25 15:04:33 -06:00
draw.text((x, y), item, font=font, fill='black')
font = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 100)
2025-04-27 16:30:02 -06:00
draw.text((100, 410), 'Out of stock?', font=font, fill='black')
draw.text((150, 560), 'Scan here:', font=font, fill='black')
2025-04-25 15:04:33 -06:00
im.save('tmp.png')
print_consumable_label('Brown paper towel')