brother_ql_wrapper.py 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. import subprocess, os
  2. from brother_ql.conversion import convert
  3. from brother_ql.backends.helpers import send
  4. from brother_ql.raster import BrotherQLRaster
  5. class BrotherQlPrinter():
  6. backend = 'pyusb'
  7. def __init__(self, model='QL-800', printer_connection='usb://0x04f9:0x209b', label_format='12', red_label=False):
  8. self.model = model
  9. self.printer = printer_connection
  10. self.label = label_format
  11. self.red_label = red_label
  12. def print_image(self, image, rotation='Auto', cut=True):
  13. qlr = BrotherQLRaster(self.model)
  14. qlr.exception_on_warning = True
  15. instructions = convert(qlr=qlr,
  16. images = [image],
  17. label=self.label,
  18. rotate = str(rotation),
  19. threshold=70.0,
  20. dither = False,
  21. compress = False,
  22. red = self.red_label,
  23. dpi_600=False,
  24. hq = True,
  25. cut = cut
  26. )
  27. send(instructions=instructions, printer_identifier=self.printer, backend_identifier=self.backend, blocking=True)