zpl_encode

Function zpl_encode 

Source
pub fn zpl_encode(image_bytes: &[u8]) -> ZplResult<(String, usize, usize)>
Expand description

Encodes raw image bytes into a ZPL-compatible hexadecimal string for use with the ^GF command.

This function converts common image formats (PNG, JPEG, etc.) to a black-and-white bitmap (1 bit per pixel). It applies Zebra’s standard ASCII compression (repeat characters G-z) to reduce string size. A pixel is considered black (1) if its luminance is below 50%, otherwise it is white (0).

This is commonly used to embed custom logos, icons, or external graphics into a ZPL label format.

§Arguments

  • image_bytes - The raw bytes of the image (e.g., from a file).

§Returns

A ZplResult containing a tuple with:

  1. The encoded string (hexadecimal with ASCII compression).
  2. Total number of bytes in the bitmap.
  3. Bytes per row (required by the ^GF command).