2. Creating rasters#

2.1. High level Raster creation#

This module offers a high-level API for converting images into a raster instruction file for the printer.

brother_ql.conversion.convert(qlr: BrotherQLRaster, images: list[str | Image], label: str, **kwargs)#

Converts one or more images to a raster instruction file.

Parameters:
  • qlr – An instance of the BrotherQLRaster class

  • images – The images to be converted. They can be filenames or instances of Pillow’s Image.

  • label – Type of label the printout should be on.

  • **kwargs – See below

Keyword Arguments:
  • cut (bool) – Enable cutting after printing the labels.

  • dither (bool) – Instead of applying a threshold to the pixel values, approximate grey tones with dithering.

  • compress (bool) – Applies packbits compression to the image data in the raster

  • red (bool) – Enables generation of a red channel for use with supported printer/label combinations

  • rotate – Whether to rotate the image (“auto”|0|90|180|270)

  • dpi_600 (bool) – Whether to enable 300x600dpi mode for supported printers (takes 600x600dpi input image)

  • hq – ???

  • threshold (int) – The threshold value to determine if a result pixel is black or white (0-255)

2.2. Low level Raster creation#

This module contains the implementation of the raster language of the Brother QL-series label printers according to their documentation and to reverse engineering efforts.

The central piece of code in this module is the class BrotherQLRaster.

class brother_ql.raster.BrotherQLRaster(model='QL-500')#

This class facilitates the creation of a complete set of raster instructions by adding them one after the other using the methods of the class. Each method call is adding instructions to the member variable data.

Instatiate the class by providing the printer model as argument.

Parameters:

model (str) – Choose from the list of available models.

Variables:
  • data (bytes) – The resulting bytecode with all instructions.

  • exception_on_warning (bool) – If set to True, an exception is raised if trying to add instruction which are not supported on the selected model. If set to False, the instruction is simply ignored and a warning sent to logging/stderr.

add_autocut(autocut=False)#
add_compression(compression=True)#

Add an instruction enabling or disabling compression for the transmitted raster image lines. Not all models support compression. If the specific model doesn’t support it but this method is called trying to enable it, either a warning is set or an exception is raised depending on the value of exception_on_warning

Parameters:

compression (bool) – Whether compression should be on or off

add_cut_every(n=1)#
add_expanded_mode()#
add_initialize()#
add_invalidate()#

clear command buffer

add_margins(dots=35)#
add_media_and_quality(rnumber)#
add_print(last_page=True)#
add_raster_data(image, second_image=None)#

Add the image data to the instructions. The provided image has to be binary (every pixel is either black or white).

Parameters:
  • image (PIL.Image.Image) – The image to be converted and added to the raster instructions

  • second_image (PIL.Image.Image) – A second image with a separate color layer (red layer for the QL-800 series)

add_status_information()#

Status Information Request

add_switch_mode()#

Switch dynamic command mode Switch to the raster mode on the printers that support the mode change (others are in raster mode already).

get_pixel_width()#
model: Model#