First, you will need pycups. Then this code should work but I cannot test it:
# Set up CUPS
conn = cups.Connection()
printers = conn.getPrinters()
printer_name = printers.keys()[0]
cups.setUser('pi')
# Save the picture to a temporary file for printing
from tempfile import mktemp
output = mktemp(prefix='jpg')
im.save(output, format='jpeg')
# Send the picture to the printer
print_id = conn.printFile(printer_name, output, "Photo Booth", {})
# Wait until the job finishes
from time import sleep
while conn.getJobs().get(print_id, None):
sleep(1)
The picture is im
, which is created at line 168. Just paste the code below this line.
For more details, you can find the snap
method in boothcam.py#L99.
This is a script I succesfully tested:
#!/usr/bin/env python
# coding: utf-8
import cups
import Image
from tempfile import mktemp
from time import sleep
# Set up CUPS
conn = cups.Connection()
printers = conn.getPrinters()
printer_name = printers.keys()[0]
cups.setUser('tiger-222')
# Image (code taken from boothcam.py)
im = Image.new('RGBA', (683, 384))
im.paste(Image.open('test.jpg').resize((683, 384)), ( 0, 0, 683, 384))
# Save data to a temporary file
output = mktemp(prefix='jpg')
im.save(output, format='jpeg')
# Send the picture to the printer
print_id = conn.printFile(printer_name, output, "Photo Booth", {})
# Wait until the job finishes
while conn.getJobs().get(print_id, None):
sleep(1)
unlink(output)