escpos-ts API - v1.0.0
    Preparing search index...

    Class EscposImage

    An image loaded from a file path or raw Buffer, pre-processed into a two-dimensional boolean pixel grid ready for ESC/POS encoding.

    Dark pixel → true Light pixel → false

    1.0.0

    Index

    Properties

    height: number

    Image height in pixels (number of rows).

    width: number

    Image width in pixels.

    widthBytes: number

    Number of bytes required to represent one row of pixels. Equals Math.ceil(width / 8).

    Methods

    • Centre the image within maxWidth pixels by padding each row with white pixels on the left and right. If the image is already as wide as or wider than maxWidth, this is a no-op.

      Parameters

      • maxWidth: number

        Target width in pixels.

      Returns void

      1.0.0

    • Yield column data buffers for ESC * column-format printing.

      Each yielded Buffer represents the vertical byte-strip for one pixel column. Bits are packed top-to-bottom, MSB at the top.

      The number of bytes per column depends on highDensity:

      • Low density (8-dot): 1 byte per column.
      • High density (24-dot): 3 bytes per column.

      Escpos.image() wraps these blobs with the ESC * header and line-feed when impl === 'bitImageColumn'.

      Parameters

      • highDensity: boolean = false

        true for 24-dot high-density mode, false for 8-dot low-density mode. Defaults to false.

      Returns Generator<Buffer<ArrayBufferLike>>

      1.0.0

    • Encode the image as a raw ESC/POS raster data payload (pixel bytes only, no GS v 0 header).

      Layout: row-major, MSB-first within each byte.

      • Bit 7 of byte 0 in each row → leftmost pixel.
      • Length = widthBytes × height bytes.

      The caller is responsible for prepending the GS v 0 command header. Escpos.image() handles this internally when impl === 'bitImageRaster'.

      Returns Buffer

      Raw pixel data buffer.

      1.0.0

    • Load an image from a file path or raw image Buffer (PNG, BMP, JPEG, GIF, TIFF).

      The image is:

      1. Composited onto a white background to flatten any alpha channel.
      2. Converted to greyscale.
      3. Thresholded at luminance 128 — any pixel darker than 128 is treated as a printed dot.

      Parameters

      • source: string | Buffer<ArrayBufferLike>

        Absolute file path or raw image file Buffer.

      Returns Promise<EscposImage>

      A resolved EscposImage instance.

      1.0.0