Skip to content

Commit

Permalink
Print photo with Cups (test 1)
Browse files Browse the repository at this point in the history
Automatically print a photo with the default printer on Cups.
  • Loading branch information
ricochebonjour committed Mar 12, 2018
1 parent 0c758f7 commit 7ed71e4
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion camera.py
Expand Up @@ -8,6 +8,7 @@

import RPi.GPIO as GPIO
import picamera
import cups

#############
### Debug ###
Expand Down Expand Up @@ -52,6 +53,20 @@
camera.resolution = (photo_w, photo_h)
camera.hflip = True # When preparing for photos, the preview will be flipped horizontally.

#################################
### Thermal Printer with CUPS ###
#################################
def printCups(photo_number, filename_prefix):
filename = filename_prefix + '/' + str(photo_number) + 'of'+ str(total_pics)+'.jpg'
image = Image.open(filename)
image.thumbnail( (384,382), Image.ANTIALIAS)
conn = cups.Connection()
printers = conn.getPrinters()
printer_name = printers.keys()[0]
cups.setUser('pi')
#Photo printed one time
conn.printFile("Printing", photo_number, "from", filename_prefix,{"copies": "1"})

####################
### Other Config ###
####################
Expand Down Expand Up @@ -272,9 +287,11 @@ def main():
prep_for_photo_screen(photo_number)
taking_photo(photo_number, filename_prefix)

#printing process
printCups(photo_number, filename_prefix)
#thanks for playing
playback_screen(filename_prefix)

# If we were doing a test run, exit here.
if TESTMODE_AUTOPRESS_BUTTON:
break
Expand Down

0 comments on commit 7ed71e4

Please sign in to comment.