bitrate16 / peripage-python

Python module and documentation for direct printing on Peripage thermal printers via bluetooth
GNU General Public License v3.0
77 stars 10 forks source link

Printing Images from a Python Script #8

Closed Zedelghem closed 2 years ago

Zedelghem commented 2 years ago

Have you thought about adding a possibility to print images through your print_service module?

Best Bj

bitrate16 commented 2 years ago

It can be done similar to this:

https://github.com/bitrate16/ppa6-python/blob/2b7ce843a07190c5b441a18247279940020d4780/print-server/main.py#L178

# Setup
service = print_service.PrintService(60, 1, 5)
service.start(PRINTER_MAC, PRINTER_MODEL)

# Open
image = PIL.open('image.png')
concentration = 1

# Wrapper
def wrap_print_image(p: ppa6.Printer):
    p.setConcentration(concenttration)
    p.printImage(img)

# Submit
service.add_print_handler(wrap_print_image)

Or with labmda

service.add_print_handler(lambda p: p.printImage(PIL.open('image.png'))
bitrate16 commented 2 years ago

Added in commit https://github.com/bitrate16/ppa6-python/commit/d7820b708a551be4dafeff1d78868215d2a489e9, untested

Zedelghem commented 2 years ago

Thank you so much! Looking into it right now.