Raspberry Pi Photobooth 打印

Posted

技术标签:

【中文标题】Raspberry Pi Photobooth 打印【英文标题】:Raspberry Pi Photobooth Printing 【发布时间】:2016-08-24 07:39:32 【问题描述】:

我已经建立了this photobooth,我正在努力弄清楚我需要向脚本中添加什么代码才能打印每张照片的副本。我已经使用杯子将我的打印机映射到树莓派上。

Here 是带有脚本的 github。

谢谢!

【问题讨论】:

【参考方案1】:

首先,您需要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)

【讨论】:

这太棒了。非常感谢!我构建了它,以便它拍摄四张照片并将它们合并为一张图像 - 每张照片都在合并图像的一个象限中。我正在尝试将代码添加到 python 脚本中,以便四张照片中的每一张都有一个边框。我尝试过的任何事情都没有接近工作。有什么建议吗? 不客气 :) 如果您认为答案很好,您可以将答案设置为已回答吗?对于您的第二个问题,请查看此链接:Adding borders to an image using python。

以上是关于Raspberry Pi Photobooth 打印的主要内容,如果未能解决你的问题,请参考以下文章