print def
This commit is contained in:
parent
3532df133d
commit
8a2970a09b
26
txt.py
26
txt.py
|
@ -84,6 +84,17 @@ def rtl_text_wrap(text, width):
|
||||||
return '\n'.join(lines)
|
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:
|
while True:
|
||||||
user_input = input("Type something (or press + for camera): ")
|
user_input = input("Type something (or press + for camera): ")
|
||||||
if user_input == "+":
|
if user_input == "+":
|
||||||
|
@ -101,11 +112,13 @@ while True:
|
||||||
print("warp: "+wrapped_text)
|
print("warp: "+wrapped_text)
|
||||||
|
|
||||||
num_lines = wrapped_text.count('\n') + 1
|
num_lines = wrapped_text.count('\n') + 1
|
||||||
|
|
||||||
font_size = img_width // 6
|
font_size = img_width // 6
|
||||||
ttfont = "5x5-Tami.ttf"
|
# ttfont = "5x5-Tami.ttf"
|
||||||
ttfont = "VarelaRound-Regular.ttf"
|
# ttfont = "VarelaRound-Regular.ttf"
|
||||||
ttfont = "fonts/xbmc-hebrew-fonts/Roboto-Bold-xbmc-il.ttf"
|
ttfont = "fonts/xbmc-hebrew-fonts/Roboto-Bold-xbmc-il.ttf"
|
||||||
font = ImageFont.truetype(ttfont, font_size)
|
font = ImageFont.truetype(ttfont, font_size)
|
||||||
|
|
||||||
line_height = font_size + 10
|
line_height = font_size + 10
|
||||||
img_height = num_lines * line_height + 200
|
img_height = num_lines * line_height + 200
|
||||||
image = Image.new('RGB', (img_width, img_height), 'white')
|
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))
|
d.text((x, y), wrapped_text, font=font, fill=(0, 0, 0))
|
||||||
image.save("output.png")
|
image.save("output.png")
|
||||||
|
|
||||||
# Step 2: Print
|
print_label("output.png")
|
||||||
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)
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user