Raspberry Pi Photobooth 打印 [英] Raspberry Pi Photobooth Printing
问题描述
我已经建立了this photobooth,我正在努力弄清楚找出我需要添加到脚本中的代码才能打印每张照片的副本.我已经使用杯子将我的打印机映射到树莓派上.
这里是带有脚本的 github.>
谢谢!
首先,您需要 pycups一>.然后这段代码应该工作,但我无法测试它:
#设置CUPSconn = cups.Connection()打印机 = conn.getPrinters()打印机名称 = 打印机.keys()[0]cups.setUser('pi')# 将图片保存到临时文件中进行打印从临时文件导入 mktemp输出 = mktemp(prefix='jpg')im.save(输出,格式='jpeg')# 将图片发送到打印机print_id = conn.printFile(printer_name, output, "Photo Booth", {})# 等待作业完成从时间导入睡眠而 conn.getJobs().get(print_id, None):睡觉(1)
图片是im
,创建于第 168 行.只需将代码粘贴到此行下方即可.
有关更多详细信息,您可以在 snap 方法rel="nofollow">boothcam.py#L99.
这是我成功测试的脚本:
#!/usr/bin/env python# 编码:utf-8进口杯子导入图片从临时文件导入 mktemp从时间导入睡眠# 设置 CUPSconn = cups.Connection()打印机 = conn.getPrinters()打印机名称 = 打印机.keys()[0]cups.setUser('tiger-222')# 图片(代码来自boothcam.py)im = Image.new('RGBA', (683, 384))im.paste(Image.open('test.jpg').resize((683, 384)), ( 0, 0, 683, 384))# 将数据保存到临时文件输出 = mktemp(prefix='jpg')im.save(输出,格式='jpeg')# 将图片发送到打印机print_id = conn.printFile(printer_name, output, "Photo Booth", {})# 等待作业完成而 conn.getJobs().get(print_id, None):睡觉(1)取消链接(输出)
I've built this photobooth, and I am struggling to figure out what code i would need to add to the script in order to get this to print a copy of each photo. I have already mapped my printer to the raspberry pi using cups.
Here is the github with the script.
Thanks!
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)
这篇关于Raspberry Pi Photobooth 打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!