Raspberry Pi Photobooth Printing

问题描述:

我已经建立了this photobooth,我正在努力弄清楚我需要添加到脚本中的代码才能打印出每张照片的副本。我已经使用杯子将我的打印机映射到覆盆子pi。Raspberry Pi Photobooth Printing

Here是与脚本github。

谢谢!

首先,您将需要pycups。那么这个代码应该工作,但我无法测试它:

# 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) 

图片是im,这是在line 168创建。只需将该代码粘贴到该行下面即可。

欲了解更多详情,您可以在boothcam.py#L99找到snap方法。

这是一个脚本,我成功地测试了:

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

这是惊人的。非常感谢!我建立了这个模型,这样就可以拍摄四张照片并将它们合并到一张图像中 - 每张照片都位于合并图像的象限中。我正在尝试将代码添加到python脚本中,以便四张照片中的每一张都有围绕它们的边框。我试过的东西都没有接近工作。有什么建议么? – odunde

+0

欢迎您:)如果您认为它很好,您可以将答案设置为答案吗?对于第二个问题,请查看以下链接:[使用python为图像添加边框](https://*.com/questions/11142851/adding-borders-to-an-image-using-python)。 –