Thermal printer prints photos from Raspberry Pi camera.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

45 lines
1017 B

#!/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()