Discord

Preparing your files

Please wait until the download is ready.

Luka's Scripting Utilities

Luka's Scripting Utilities

by Luka S.J.

A pack full of various scripting utilities to ease your development!

v4.1.135,194
Download144 KB

QR Code Generator

QRCodeGenerator encodes an arbitrary string into a scannable QR code Bitmap
using byte-mode encoding with full Reed-Solomon error correction.

bmp = QRCodeGenerator.new("https://luka-sj.com").generate
sprite.bitmap = bmp

Usage

QRCodeGenerator.new(data, version: nil, unit_size: 4, color_white: ..., color_black: ...)

  • data the string to encode
  • version the QR version (size). Leave nil to auto-select the smallest version that fits
  • unit_size pixel size of each module (default 4)
  • color_white / color_black the module colours (default white / black)

Then:

  • generator.generate renders the final QR bitmap, including the 4-module quiet-zone border

Choosing a version

  • QRCodeGenerator.recommend_version(data, mode = :byte) the smallest supported version that fits the data (or nil)
  • QRCodeGenerator.version_capacity(version, mode = :byte) the approximate byte capacity of a version

Supported range

  • Versions 2–4 only (version 1 is not supported).
  • Byte mode encoding (any string data).
  • Error correction level L (≈ 7% recovery).

If the data exceeds the capacity of all supported versions — or an explicit
version: is out of range — construction raises ArgumentError.

Internals

The generator is built from focused subcomponents, exposed in case you want to
work at a lower level:

  • QRCodeGenerator::Config — version/error-level capacity, matrix size and alignment-pattern positions
  • QRCodeGenerator::Encoder — turns the input string into the encoded bit stream
  • QRCodeGenerator::ReedSolomon — error-correction codewords (with a GF256 Galois-field helper)
  • QRCodeGenerator::Matrix — the module grid with finder and alignment patterns