print def

This commit is contained in:
yair-mantis 2024-01-09 11:17:33 +02:00
parent 3532df133d
commit 8a2970a09b

26
txt.py
View File

@ -84,6 +84,17 @@ def rtl_text_wrap(text, width):
return '\n'.join(lines)
def print_label(image_path, printer_ql550="0x2016", printer_id1="000M6Z401370"):
command = (
f"/home/{username}/.local/bin/brother_ql -b pyusb --model QL-550 "
f"-p usb://0x04f9:{printer_ql550}/{printer_id1} print -l 62 {image_path}"
)
process = subprocess.run(command, shell=True, capture_output=True, text=True)
if "The system cannot find the path specified." in process.stderr:
print("printer not connected")
while True:
user_input = input("Type something (or press + for camera): ")
if user_input == "+":
@ -101,11 +112,13 @@ while True:
print("warp: "+wrapped_text)
num_lines = wrapped_text.count('\n') + 1
font_size = img_width // 6
ttfont = "5x5-Tami.ttf"
ttfont = "VarelaRound-Regular.ttf"
# ttfont = "5x5-Tami.ttf"
# ttfont = "VarelaRound-Regular.ttf"
ttfont = "fonts/xbmc-hebrew-fonts/Roboto-Bold-xbmc-il.ttf"
font = ImageFont.truetype(ttfont, font_size)
line_height = font_size + 10
img_height = num_lines * line_height + 200
image = Image.new('RGB', (img_width, img_height), 'white')
@ -117,11 +130,4 @@ while True:
d.text((x, y), wrapped_text, font=font, fill=(0, 0, 0))
image.save("output.png")
# Step 2: Print
printer_ql550 = "0x2016"
printer_id1 = "000M6Z401370"
command = (
f"/home/{username}/.local/bin/brother_ql -b pyusb --model QL-550 "
f"-p usb://0x04f9:{printer_ql550}/{printer_id1} print -l 62 output.png"
)
subprocess.run(command, shell=True)
print_label("output.png")