glqr
Types
Information for error correction table https://www.thonky.com/qr-code-tutorial/error-correction-table
pub type ECInfo {
ECInfo(
data_codewords: Int,
ec_codewords_per_block: Int,
group1_blocks: Int,
group1_block_size: Int,
group2_blocks: Int,
group2_block_size: Int,
)
}
Constructors
-
ECInfo( data_codewords: Int, ec_codewords_per_block: Int, group1_blocks: Int, group1_block_size: Int, group2_blocks: Int, group2_block_size: Int, )
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)
A module in the QR code matrix, which can be either dark or light
pub type Module {
Dark
Light
}
Constructors
-
Dark -
Light
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(List(List(Module)), GenerateError)
Generate a QR code matrix based on the provided config
This can then be piped into to_printable or to_svg to get a visual representation of the QR code
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_printable(matrix: List(List(Module))) -> String
Convert the QR code matrix 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