Instantly share code, notes, and snippets.

@fvdbosch fvdbosch/ Secret
Last active Oct 7, 2018

What would you like to do?
Raspberry Pi Photo Booth using Touch Screen & Thermal Printer
from __future__ import print_function
import os, time, Image, sys
from Adafruit_Thermal import *
import kivy
kivy.require('1.0.6') # replace with your current kivy version !
from import App
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.image import Image as kivyImage
from kivy.clock import Clock
from import Color, Rectangle
# Some variables
photoPath = "/home/pi/photobooth/"
photoName = time.strftime("%Y%m%d%H%M%S") + "_photobooth.jpg"
photoResize = 512, 384
photoTitle = "Fred's Photo Booth!"
# Define printer
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
# Callback function for photo button
def photo_callback(obj):
# Define filename with timestamp
photoName = time.strftime("%Y%m%d%H%M%S") + "_photobooth.jpg"
# Take photo using "raspistill"
os.system("sudo raspistill -p '144,48,512,384' --vflip -w 1920 -h 1440 -o " + photoPath + photoName)
# Resize the high res photo to create thumbnail + photoName).resize(photoResize, Image.ANTIALIAS).save(photoPath + "thumbnail.jpg")
# Callback function for print button
def print_callback(obj):
# Rotate the thumbnail for printing + "thumbnail.jpg").transpose(2).save(photoPath + "thumbnail-rotated.jpg")
# Print the foto
printer.begin(90) # Warmup time
printer.setTimes(40000, 3000) # Set print and feed times
printer.justify('C') # Center alignment
printer.printImage( + "line-top.png"), True)
printer.printImage( + "line-bottom.png"), True)
printer.feed(1) # Add a blank line
printer.printImage( + "thumbnail-rotated.jpg"), True) # Specify image to print
printer.feed(1) # Add a blank line
printer.printImage( + "qr-code.png"), True) # Specify image to print
printer.feed(3) # Add a few blank lines
class MyApp(App):
# Display the latest thumbnail
photo = kivyImage(source="/home/pi/photobooth/thumbnail.jpg")
def build(self):
# Set up the layout
photobox = GridLayout(cols=3, spacing=10, padding=10)
# Create the UI objects (and bind them to callbacks, if necessary)
photoButton = Button(text="photo", size_hint=(.20, 1)) # Button: 20% width, 100% height
photoButton.bind(on_press=photo_callback) # when pressed, trigger the photo_callback function
printButton = Button(text="print", size_hint=(.20, 1)) # Button: 20% width, 100% height
printButton.bind(on_press=print_callback) # when pressed, trigger the print_callback function
# Periodically refresh the displayed photo using the callback function
Clock.schedule_interval(self.callback, 1)
# Add the UI elements to the layout
return photobox
# Callback for thumbnail refresh
def callback(self, instance):
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment