escpos/image

Module to parse and dither PBM/PGM images to be printed on monochrome printers. There are printers that can print grayscale or even color, if you want to do that, you’ll need to implement that yourself and/or leverage the protocol module directly.

80mm printers usually have a maximum of 640 dots width. There is no validation so please check your image beforehand.

Thank you jak for the pgm reading and bayer dithering 💕

Types

Grayscale image that needs dithering.

pub opaque type GrayscaleImage
pub opaque type ImageError

Monochrome image with byte aligned rows, ready to be printed

pub opaque type PrintableImage

Values

pub fn bayer_2x2_matrix(row: Int, column: Int) -> Int
pub fn bayer_4x4_matrix(row: Int, column: Int) -> Int
pub fn dither_bayer2x2(
  image: GrayscaleImage,
  bias: Int,
) -> PrintableImage

Bayer dithering using a 2x2 matrix

pub fn dither_bayer4x4(
  image: GrayscaleImage,
  bias: Int,
) -> PrintableImage

Bayer dithering using a 4x4 matrix

pub fn dither_ign(image: GrayscaleImage) -> PrintableImage

Interleaved Gradient Noise dithering More natural look for photos Nice blog post explaining it: https://blog.demofox.org/2022/01/01/interleaved-gradient-noise-a-different-kind-of-low-discrepancy-sequence/

pub fn from_pbm(
  pbm: BitArray,
) -> Result(PrintableImage, ImageError)

Parse a PBM image. PBM is already monocrhome and ready to be printed.

pub fn from_pgm(
  pgm: BitArray,
) -> Result(GrayscaleImage, ImageError)

Parse a PGM image. PGM is grayscale and needs to be dithered.

Search Document