Python 覆盆子皮光室印刷

Python 覆盆子皮光室印刷,python,printing,raspberry-pi,Python,Printing,Raspberry Pi,我已经建立了photobooth,我正在努力找出需要添加到脚本中的代码,以便打印每张照片的副本。我已经用纸杯将打印机映射到覆盆子圆周率 是带有脚本的github 谢谢 首先,您需要。那么这段代码应该可以工作,但我无法测试它: # Set up CUPS conn = cups.Connection() printers = conn.getPrinters() printer_name = printers.keys()[0] cups.setUser('pi') # Save the pic

我已经建立了photobooth,我正在努力找出需要添加到脚本中的代码,以便打印每张照片的副本。我已经用纸杯将打印机映射到覆盆子圆周率

是带有脚本的github

谢谢

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

# 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
,创建于。只要把代码贴在这行下面就行了

有关详细信息,您可以在中找到
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脚本添加代码,以便四张照片的周围都有边框。我所做的一切都无法奏效。有什么建议吗?欢迎:)如果你认为答案是好的,你能把它设为已回答吗?关于第二个问题,请检查以下链接:。