glqr
Types
Error correction levels for QR codes
- L: Recovers 7% of data
- M: Recovers 15% of data (default)
- Q: Recovers 25% of data
- H: Recovers 30% of data https://www.thonky.com/qr-code-tutorial/data-encoding (Step 1)
pub type ErrorCorrectionLevel {
L
M
Q
H
}
Constructors
-
L -
M -
Q -
H
Error type for QR code generation
pub type GenerateError {
EmptyValue(String)
InvalidVersion(Int)
ProvidedValueExceedsCapacity(value_length: Int, capacity: Int)
InvalidNumericEncoding(String)
InvalidAlphanumericEncoding(String)
InvalidUtf8Encoding(String)
InvalidRemainingBits(String)
}
Constructors
-
EmptyValue(String) -
InvalidVersion(Int) -
ProvidedValueExceedsCapacity(value_length: Int, capacity: Int) -
InvalidNumericEncoding(String) -
InvalidAlphanumericEncoding(String) -
InvalidUtf8Encoding(String) -
InvalidRemainingBits(String)
Generated QR code containing the module data
Use to_printable, to_svg, or to_bits to convert to different formats
pub opaque type Qr
Config for QR code
value: The string value to encode in the QR codeerror_correction: The error correction level to use (L, M, Q, H) M is the defaultmin_version: The minimum QR code version to use (1-40) 1 is the default
pub type QrConfig {
QrConfig(
value: String,
error_correction: ErrorCorrectionLevel,
min_version: Int,
)
}
Constructors
-
QrConfig( value: String, error_correction: ErrorCorrectionLevel, min_version: Int, )
Values
pub fn error_correction(
config: QrConfig,
level: ErrorCorrectionLevel,
) -> QrConfig
Set the error correction level for the QR code config
- L: Recovers 7% of data
- M: Recovers 15% of data (default)
- Q: Recovers 25% of data
- H: Recovers 30% of data
pub fn generate(config: QrConfig) -> Result(Qr, GenerateError)
Generate a QR code based on the provided config
Returns a Qr that can be converted to different formats using to_printable, to_svg, or to_bits
pub fn min_version(config: QrConfig, version: Int) -> QrConfig
Set the minimum version for the QR code config (1-40) Version 1 is 21x21 Version 40 is 177x177
pub fn new(value: String) -> QrConfig
Create a new QR code config with the provided value and default settings for error correction and minimum version Default error correction level is M (15% recovery) Default minimum version is 1 (21x21)
pub fn to_bits(qr: Qr) -> #(Int, BitArray)
Convert the QR code into a tuple of (size, bits) where size is the width/height Each bit represents a module: 1 = Dark, 0 = Light To access module at (row, col): bit index = row * size + col
pub fn to_printable(qr: Qr) -> String
Convert the QR code into a printable string representation using Unicode block characters You must use io.println to print this rather than echo as echo will preserve the newlines