Hacked together printer functions

This commit is contained in:
TT-392 2024-09-15 12:20:53 +02:00
parent 0accf4dc96
commit 31153bb679
4 changed files with 22 additions and 14 deletions

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "flask/epson"]
path = flask/epson
url = https://mid-kid.root.sx/git/mid-kid/epson.git

1
flask/epson Submodule

@ -0,0 +1 @@
Subproject commit 37ab1729e6cdb212619bd4c12097ef0d926c0c2c

View file

@ -9,4 +9,4 @@ def format_image(path):
return new_image
format_image("static/text/text.png")
#format_image("static/text/text.png").save("output.png")

View file

@ -1,23 +1,27 @@
dev_path="/dev/usb/lp0"
from format_image import format_image
from PIL import Image
import os
def print_text(stream, text):
stream.write(text.encode('utf-8'))
def cut_paper(stream):
stream.write(b'\x1DVA\xc8')
def print_image(image):
buffer = io.BytesIO()
image.save(buffer, format='PBM')
pbm_base64 = base64.b64encode(buffer.getvalue()).decode('utf-8')
def print_text(text):
stream = open('/dev/usb/lp0', 'wb')
print_text(stream, "test\n")
cut_paper(stream)
stream.write(text.encode('utf-8'))
stream.close()
def cut_paper():
stream = open('/dev/usb/lp0', 'wb')
stream.write(b'\x1DV\x41\0')
stream.close()
def print_image(image):
image.save("/tmp/image.png")
# 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()