# Z64 image encoding

Source: https://openzpl.com/glossary/z64/ (updated 2026-10-20)

Z64 is a compressed way to send image data in ZPL: the bitmap is compressed with zlib (deflate), encoded in Base64 and followed by a CRC checksum. It draws exactly the same image as ASCII hex in a fraction of the characters.

## The format

A Z64 field looks like :Z64:<base64 data>:<crc> and goes where the hex data would go in ^GF or ~DG. The byte counts in ^GF still describe the UNcompressed bitmap: one bit per dot, rows padded to whole bytes.

- Pack the image to 1 bit per dot, 1 = black, each row rounded up to whole bytes.
- Compress the bytes with zlib.
- Encode the result in Base64.
- Append a colon and the CRC-16 of the Base64 text, as 4 hex digits.

## Same image, two encodings

A 64 × 64 dot ring is 512 bytes of bitmap. In ASCII hex that is 1,024 characters; in Z64 it is 246. Both render identically.

ASCII hex (^GFA):
```zpl
^XA
^FO40,40^GFA,512,512,8,000000000000000000000000000000000000001FF8000000000001FFFF80000000000FFFFFF0000000003FFFFFFC00000000FFFFFFFF00000001FFFFFFFF80000007FFFFFFFFE000000FFFFFFFFFF000001FFFFFFFFFF800003FFFFFFFFFFC00007FFFFFFFFFFE0000FFFFFFFFFFFF0000FFFFF00FFFFF0001FFFF8001FFFF8003FFFE00007FFFC003FFF800001FFFC007FFF000000FFFE007FFE0000007FFE00FFFC0000003FFF00FFF80000001FFF00FFF80000001FFF01FFF00000000FFF81FFF0007E000FFF81FFE001FF8007FF81FFE003FFC007FF83FFE007FFE007FFC3FFC007FFE003FFC3FFC00FFFF003FFC3FFC00FFFF003FFC3FFC00FFFF003FFC3FFC00FFFF003FFC3FFC00FFFF003FFC3FFC00FFFF003FFC3FFC007FFE003FFC3FFE007FFE007FFC1FFE003FFC007FF81FFE001FF8007FF81FFF0007E000FFF81FFF00000000FFF80FFF80000001FFF00FFF80000001FFF00FFFC0000003FFF007FFE0000007FFE007FFF000000FFFE003FFF800001FFFC003FFFE00007FFFC001FFFF8001FFFF8000FFFFF00FFFFF0000FFFFFFFFFFFF00007FFFFFFFFFFE00003FFFFFFFFFFC00001FFFFFFFFFF800000FFFFFFFFFF0000007FFFFFFFFE0000001FFFFFFFF80000000FFFFFFFF000000003FFFFFFC000000000FFFFFF00000000001FFFF8000000000001FF800000000000000000000000000000000000000^FS
^FO140,60^A0N,30,30^FDASCII hex: 1024 characters^FS
^XZ
```

Z64:
```zpl
^XA
^FO40,40^GFA,512,512,8,:Z64:eNqVkcsNwyAQRIk4cKQESnFpuDRKoYQcOSDGO2sPUpJTVjZPNvudDeHHynC8gJPMwJs8gEnC7L52h0R2d3PHQg5394BKrjuMgeZkrp6db+RdRYuMKWiJOTJ6Yk47MloIkTEna24WeC/DmDq52Hclj2k8Vqj2TH7wl9Gq/sU77smjvLuO6j59fPenvjWH5tKcmls6SJetk3STjtJVOkt37UF72XvS3rRH7fXTLgbp9NU=:0CE2^FS
^FO140,60^A0N,30,30^FDZ64: 246 characters^FS
^XZ
```

## Z64, B64 and ASCII hex

B64 is Base64 without compression: about a third larger than the bitmap, useful when the image doesn't compress. ASCII hex doubles the size but is easy to read and to debug. Z64 is the smallest for logos and text-like images, which compress well. Large photos, dithered, compress poorly in any of them. The guide images in ZPL shows how to produce ^GF from a PNG.

**What happens if the CRC is wrong?** The OpenZPL engine doesn't check it: an image with a wrong CRC still renders, so a preview can't catch it. A printer may reject the image, so compute the CRC-16 over the Base64 text, not over the compressed bytes, and test on the printer.
