2024-09-25 19:48:36 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2024-09-15 18:53:03 +00:00
|
|
|
dev_path="/dev/usb/lp0"
|
2024-09-26 18:38:41 +00:00
|
|
|
from process_image import *
|
2024-09-15 18:53:03 +00:00
|
|
|
from PIL import Image
|
|
|
|
import ctypes
|
|
|
|
import io
|
2024-09-17 22:11:43 +00:00
|
|
|
import time
|
2024-09-15 18:53:03 +00:00
|
|
|
|
|
|
|
printer = ctypes.CDLL('./epson/library_bridge.so')
|
|
|
|
|
|
|
|
def print_text(text):
|
2024-09-17 22:11:43 +00:00
|
|
|
time.sleep(0.1)
|
|
|
|
|
2024-09-15 18:53:03 +00:00
|
|
|
try:
|
|
|
|
printer.print_text(b"/dev/usb/lp0", text.encode('utf-8'))
|
|
|
|
except Exception as e:
|
|
|
|
print(f"An error occurred: {e}")
|
|
|
|
|
|
|
|
def cut_paper():
|
2024-09-17 22:11:43 +00:00
|
|
|
time.sleep(0.1)
|
|
|
|
|
2024-09-15 18:53:03 +00:00
|
|
|
try:
|
|
|
|
printer.cut(b"/dev/usb/lp0")
|
|
|
|
except Exception as e:
|
|
|
|
print(f"An error occurred: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
def print_image(image):
|
2024-09-17 22:11:43 +00:00
|
|
|
time.sleep(0.1)
|
|
|
|
|
2024-09-15 18:53:03 +00:00
|
|
|
Bytes = io.BytesIO()
|
|
|
|
image.save(Bytes, format='PNG')
|
|
|
|
Bytes = Bytes.getvalue()
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
printer.print_image(b"/dev/usb/lp0", Bytes, len(Bytes))
|
|
|
|
except Exception as e:
|
|
|
|
print(f"An error occurred: {e}")
|
|
|
|
|
|
|
|
# I'm sorry
|
|
|
|
#os.system("cd epson/; ./print_image.sh /tmp/image.png; cd ..")
|
|
|
|
|
|
|
|
#image = format_image("static/text/text.png")
|
|
|
|
#image.save("/tmp/image.png")
|
|
|
|
#print_image(image)
|
|
|
|
#cut_paper()
|
|
|
|
|
|
|
|
|