Hacked together printer functions
This commit is contained in:
parent
0accf4dc96
commit
31153bb679
4 changed files with 22 additions and 14 deletions
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal 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
1
flask/epson
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 37ab1729e6cdb212619bd4c12097ef0d926c0c2c
|
|
@ -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")
|
||||
|
|
|
@ -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):
|
||||
def print_text(text):
|
||||
stream = open('/dev/usb/lp0', 'wb')
|
||||
stream.write(text.encode('utf-8'))
|
||||
stream.close()
|
||||
|
||||
def cut_paper(stream):
|
||||
stream.write(b'\x1DVA\xc8')
|
||||
def cut_paper():
|
||||
stream = open('/dev/usb/lp0', 'wb')
|
||||
stream.write(b'\x1DV\x41\0')
|
||||
stream.close()
|
||||
|
||||
def print_image(image):
|
||||
buffer = io.BytesIO()
|
||||
image.save(buffer, format='PBM')
|
||||
image.save("/tmp/image.png")
|
||||
|
||||
pbm_base64 = base64.b64encode(buffer.getvalue()).decode('utf-8')
|
||||
# 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()
|
||||
|
||||
stream = open('/dev/usb/lp0', 'wb')
|
||||
|
||||
print_text(stream, "test\n")
|
||||
cut_paper(stream)
|
||||
|
||||
stream.close()
|
||||
|
||||
|
|
Loading…
Reference in a new issue