label_printer/flask/print.py

28 lines
575 B
Python
Raw Normal View History

2024-09-14 18:49:57 +00:00
dev_path="/dev/usb/lp0"
2024-09-15 10:20:53 +00:00
from format_image import format_image
from PIL import Image
import os
2024-09-14 18:49:57 +00:00
2024-09-15 10:20:53 +00:00
def print_text(text):
stream = open('/dev/usb/lp0', 'wb')
2024-09-14 18:49:57 +00:00
stream.write(text.encode('utf-8'))
2024-09-15 10:20:53 +00:00
stream.close()
2024-09-14 18:49:57 +00:00
2024-09-15 10:20:53 +00:00
def cut_paper():
stream = open('/dev/usb/lp0', 'wb')
stream.write(b'\x1DV\x41\0')
stream.close()
2024-09-14 18:49:57 +00:00
def print_image(image):
2024-09-15 10:20:53 +00:00
image.save("/tmp/image.png")
2024-09-14 18:49:57 +00:00
2024-09-15 10:20:53 +00:00
# I'm sorry
os.system("cd epson/; ./print_image.sh /tmp/image.png; cd ..")
2024-09-14 18:49:57 +00:00
2024-09-15 10:20:53 +00:00
image = format_image("static/text/text.png")
image.save("/tmp/image.png")
print_image(image)
cut_paper()
2024-09-14 18:49:57 +00:00