glqr

Package VersionHex 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

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
- [x] Import as local module
- [x] Data Analysis
    - [x] Numeric
    - [x] Alphanumeric
    - [x] Byte
    - [ ] Kanji
- [x] Data Encoding
    - [x] Mode Indicator
    - [x] Character Count Indicator
    - [x] Data Bits
    - [x] Terminator
    - [x] Pad Bits
- [x] Error correction
- [x] QR Code Structure
- [x] Draw Matrix
- [x] Add Snapshot Testing
- [ ] Add more Snapshot testing
- [x] Add Lustre example
- [x] Use matrix with custom QrCode type with bitarray instead of list of lists
- [x] Add to_bits feature

## References
[Thonky's QR Code Tutorial](https://www.thonky.com/qr-code-tutorial)

[IODevs elixir qr code library](https://github.com/iodevs/qr_code)

[SiliconJungles elixir qr code library](https://github.com/SiliconJungles/eqrcode)

[Nayuki QR Code Step by Step](https://www.nayuki.io/page/creating-a-qr-code-step-by-step)

[Gears BitArray Blog Post](https://gearsco.de/blog/bit-array-syntax/)