12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import subprocess, os
- from brother_ql.conversion import convert
- from brother_ql.backends.helpers import send
- from brother_ql.raster import BrotherQLRaster
- class BrotherQlPrinter():
- backend = 'pyusb'
- def __init__(self, model='QL-810W', printer_connection='usb://0x04f9:0x209c', label_format='12', red_label=False, dpi_600=False):
- self.model = model
- self.printer = printer_connection
- self.label = label_format
- self.red_label = red_label
- self.dpi_600 = dpi_600
- def print_image(self, image, rotation='Auto', cut=True):
- qlr = BrotherQLRaster(self.model)
- qlr.exception_on_warning = True
- instructions = convert(qlr=qlr,
- images = [image],
- label=self.label,
- rotate = str(rotation),
- threshold=70.0,
- dither = False,
- compress = False,
- red = self.red_label,
- dpi_600=self.dpi_600,
- hq = True,
- cut = cut
- )
- send(instructions=instructions, printer_identifier=self.printer, backend_identifier=self.backend, blocking=True)
- def print_label(label):
- printer = BrotherQlPrinter(label_format=label.ql_format, red_label=label.red_label, dpi_600=label.dpi_600)
- printer.print_image(label.get_pillow_image(), rotation=label.ql_rotation, cut=True)
- def print_labels(labels):
-
- printer = BrotherQlPrinter(label_format=labels[0].ql_format, red_label=labels[0].red_label, dpi_600=labels[0].dpi_600)
- for label in labels[:-1]:
- printer.print_image(label.get_pillow_image(), rotation=label.ql_rotation, cut=False)
- printer.print_image(labels[-1].get_pillow_image(), rotation=labels[-1].ql_rotation, cut=True)
|