element.version === currentVersion)) { versionNodes.unshift({ version: currentVersion, url: "#" }); } document.querySelector("#project-version").innerHTML = versionNodes.reduce( (acc, element) => { const status = currentVersion === element.version ? "selected disabled" : ""; return ` ${acc} `; }, `
glqr · v1.1.0

glqr

Package Version Hex Docs

gleam add glqr

Display QR Code

import gleam/io
import glqr as qr

pub fn main() -> Nil {
  let assert Ok(code) =
    qr.new("HELLO WORLD")
    |> qr.generate()

  code
  |> qr.to_printable()
  |> io.println() // YOU CANT USE ECHO AS IT PRESERVES THE NEWLINE
}

Config Options

  • Error Correction Level

    • L (Low, 7% of damage to image be restored)
    • M (Medium, 15% of damage to image be restored)
    • Q (Quartile, 25% of damage to image be restored)
    • H (High, 30% of damage to image be restored)
  • Minimum Version (1-40, default is 1)

    • Version 1: 21x21 matrix
    • Version 40: 177x177 matrix
import gleam/io
import glqr as qr

pub fn main() -> Nil {
  let assert Ok(code) =
    qr.new("HELLO WORLD")
    |> qr.error_correction(qr.L)
    |> qr.min_version(10)
    |> qr.generate()

  code
  |> qr.to_printable()
  |> io.println() // YOU CANT USE ECHO AS IT PRESERVES THE NEWLINE
}

Save SVG

import glqr as qr
import simplifile

pub fn main() -> Nil {
  let assert Ok(code) =
    qr.new("HELLO WORLD")
    |> qr.generate()

  let svg =
    code
    |> qr.to_svg()

  let assert Ok(_) = simplifile.write("output.svg", svg)
  Nil
}

Simple Lustre Example

import gleam/int
import glqr
import lustre
import lustre/attribute
import lustre/element

fn render_qr(value: String, size: Int) {
  let assert Ok(matrix) =
    glqr.new(value)
    |> glqr.generate()

  let svg = glqr.to_svg(matrix)

  lustre.element(element.unsafe_raw_html(
    "",
    "div",
    [attribute.style("max-width", int.to_string(size) <> "px")],
    svg,
  ))
}

pub fn main() {
  let app = render_qr("https://github.com/lustre-labs/lustre", 150)
  let assert Ok(_) = lustre.start(app, "#app", Nil)

  Nil
}

Further documentation can be found at https://hexdocs.pm/glqr.

Development

gleam run   # Run the project
gleam test  # Run the tests

TODO

  • Import as local module
  • Data Analysis
    • Numeric
    • Alphanumeric
    • Byte
    • Kanji
  • Data Encoding
    • Mode Indicator
    • Character Count Indicator
    • Data Bits
    • Terminator
    • Pad Bits
  • Error correction
  • QR Code Structure
  • Draw Matrix
  • Add Snapshot Testing
  • Add more Snapshot testing
  • Add Lustre example
  • Use matrix with custom QrCode type with bitarray instead of list of lists
  • Add to_bits feature

References

Thonky’s QR Code Tutorial

IODevs elixir qr code library

SiliconJungles elixir qr code library

Nayuki QR Code Step by Step

Gears BitArray Blog Post

Search Document