2016-08-24 271 views
0

我已經建立了this photobooth,我正在努力弄清楚我需要添加到腳本中的代碼才能打印出每張照片的副本。我已經使用杯子將我的打印機映射到覆盆子pi。Raspberry Pi Photobooth Printing

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) 
+0

這是驚人的。非常感謝!我建立了這個模型,這樣就可以拍攝四張照片並將它們合併到一張圖像中 - 每張照片都位於合併圖像的象限中。我正在嘗試將代碼添加到python腳本中,以便四張照片中的每一張都有圍繞它們的邊框。我試過的東西都沒有接近工作。有什麼建議麼? – odunde

+0

歡迎您:)如果您認爲它很好,您可以將答案設置爲答案嗎?對於第二個問題,請查看以下鏈接:[使用python爲圖像添加邊框](https://stackoverflow.com/questions/11142851/adding-borders-to-an-image-using-python)。 –