diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..b45dcdf --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "flask/epson"] + path = flask/epson + url = https://mid-kid.root.sx/git/mid-kid/epson.git diff --git a/flask/epson b/flask/epson new file mode 160000 index 0000000..37ab172 --- /dev/null +++ b/flask/epson @@ -0,0 +1 @@ +Subproject commit 37ab1729e6cdb212619bd4c12097ef0d926c0c2c diff --git a/flask/format_image.py b/flask/format_image.py index 98c9409..a80d6da 100644 --- a/flask/format_image.py +++ b/flask/format_image.py @@ -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") diff --git a/flask/print.py b/flask/print.py index 0ea22e2..5425d0a 100644 --- a/flask/print.py +++ b/flask/print.py @@ -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()