QRCode

Draw bytes to grids

QRCode assumes the data has already been encoded into codewords. This class handles drawing to a Grid based on mask, version, ecl, and codewords.

constructor

new QRCode({ mask, version, ecl, codewords })

  • mask: number 0-7 specifying which mask to use
  • version: number 1-40 specifying which version to use
  • ecl: number 0-3 specifying which ecl to use
  • codewords: Uint8Array with each item representing a byte
import { QRCode } from 'qrsart'

let qr = new QRCode({
  version: 2,
  ecl: 2, //0=low 1=medium 2=quartile 3=high
  mask: 6,
  codewords: generateCodewords()
})

size

qr.size

The number of pixels per row and col. size = version * 4 + 17

Grids

Each QRCode instance has the following grids:

grid qr.grid
functional_grid qr.functional_grid
data_grid qr.data_grid
finder_grid qr.finder_grid
timing_grid qr.timing_grid
alignment_grid qr.alignment_grid
format_grid qr.format_grid

Serialization

Useful for splitting encoding and graphics logic.

toBuffer

qr.toBuffer()

Serializes the QR Code into a Uint8Array.

  • First byte encodes the version
  • Second byte encodes mask and ecl
  • Subsequent bytes encode codewords

fromBuffer

QRCode.fromBuffer(buf)

Returns a new QRCode instance given a Uint8Array. The inverse of toBuffer().

toString

qr.toString()

Converts the result of qr.toBuffer() into a base64 string, useful for compact JSON and HTML storage of QR encodings.

fromString

QRCode.fromString()

Returns a new QRCode instance given a base64 string. The inverse of toString().