Raster¶
Bridge between PIL.Image objects and ESC/POS raster byte streams.
This module is pure (no I/O) and is responsible for turning a PIL image
into the byte payload of the GS v 0 (raster bit image) command that
the PT-210 firmware uses to print bitmaps.
Pillow is imported lazily inside each function so that the rest of the
SDK (commands, transport, …) can still be used on installations
where Pillow is not available.
- goojprt.raster.image_to_raster(image) bytes[source]¶
Convert a PIL image into the
GS v 0raster payload.The image is first converted to 1-bit mode, then either cropped or padded with white to exactly
PAPER_WIDTH_PXpixels wide. The output consists of theGS v 0header (normal mode; width and height encoded as little-endian 16-bit values), followed by the pixel data in row-major order with eight pixels per byte (MSB = leftmost pixel;1= black,0= white).- Parameters:
image – PIL image in any mode. It will be converted to mode
"1"internally.- Returns:
A full ESC/POS
GS v 0command ready to send to the printer.
- goojprt.raster.image_to_raster_strips(image, strip_height: int = 24) list[bytes][source]¶
Split image into horizontal strips and return each as a
GS v 0payload.Each strip is a self-contained raster command. Consecutive strips are seamless on paper because the printer’s paper motor advances by exactly the number of rows declared in each
GS v 0header.- Parameters:
image – PIL image in any mode. Converted to
"1"internally.strip_height – Number of rows per strip (default 24 → 1 152 bytes of pixel data per strip, safe for small printer buffers).
- Returns:
List of
GS v 0byte payloads, one per strip.
- goojprt.raster.pad_image_to_paper_width(image, align: Align)[source]¶
Pad a narrower image to
PAPER_WIDTH_PXwith white background.Images wider than or equal to the paper width are returned unchanged. Used for objects (typically barcodes such as PDF417) whose rendered width is smaller than the print head and need to be positioned on the paper without being stretched.
- Parameters:
image – PIL image in mode
"1".align – Horizontal alignment inside the padded canvas.
- Returns:
A PIL image with width equal to
PAPER_WIDTH_PX.