Thermal-Printer-Camera/tpc.py

46 lines
1017 B
Python
Raw Permalink Normal View History

2021-06-26 15:53:16 +00:00
#!/usr/bin/env python3
from escpos import printer
from picamera import PiCamera
from PIL import Image
from io import BytesIO
import time
p = printer.Usb(0x0493, 0x8760, in_ep=0x81, out_ep=0x03)
camera = PiCamera()
camera.resolution = (284, 284)
def capture(width=284, height=284):
stream = BytesIO()
camera.resolution = (width, height)
camera.capture(stream, format='jpeg')
stream.seek(0)
return stream
def main():
# wait for camera to initialize
sleep(1)
image = Image.open(capture(284,284))
image.seek(0)
background = Image.open("background.png")
foreground = Image.open("background.png")
background.paste(image, (50,50))
background.paste(foreground, (0, 0), foreground)
# Optional: save image
# timestr = time.strftime("%Y%m%d-%H%M%S")
#background.save(timestr+".png", "PNG")
p.image(background, high_density_vertical=True, high_density_horizontal=True, fragment_height=1)
if __name__ == '__main__':
main()