Zuerst benötigen Sie pycups. Dann ist dieser Code sollte Arbeit, aber ich kann es nicht testen:
# 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)
Das Bild ist im
, die bei line 168 erstellt wird. Fügen Sie einfach den Code unter dieser Zeile ein.
Für weitere Details finden Sie die snap
Methode in boothcam.py#L99.
Dies ist ein Skript, das ich erfolgreich getestet:
#!/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)
Das ist erstaunlich. Vielen Dank! Ich habe das so erstellt, dass es vier Fotos benötigt und sie zu einem Bild zusammenfügt - mit jedem Foto in einem Quadranten des zusammengeführten Bildes. Ich versuche, Code zum Python-Skript hinzuzufügen, so dass jedes der vier Fotos einen Rahmen um sie herum hat. Nichts, was ich versucht habe, kommt der Arbeit nahe. Irgendwelche Vorschläge? – odunde
Sie sind willkommen :) Können Sie die Antwort als beantwortet, wenn Sie denken, dass es gut ist? Für Ihre zweite Frage, überprüfen Sie diesen Link: [Hinzufügen von Rändern zu einem Bild mit Python] (https://stackoverflow.com/questions/11142851/adding-borders-to-an-image-using-python). –