ondrej-tucek

ondrej-tucek

QRCode - a library for generating QR code

Hi folks!

We’ve just finished (me and @smita) our new QRCode library for Elixir. Now you can generate QR code whenever you’ll want… :tada:

Basic usage looks like:

iex> qr = QRCode.create("Hello World")
iex> qr |> Result.and_then(&QRCode.Svg.save_as(&1,"/path/to/hello.svg"))
{:ok, "/path/to/hello.svg"}

If you want to change, for example, ecc level and the color of QR code you can write

iex> settings = %QRCode.SvgSettings{qrcode_color: {17, 170, 136}}
iex> qr = QRCode.create("quiz_string", :high)
iex> qr |> Result.and_then(&QRCode.Svg.save_as(&1, "/path/to/quiz.svg", settings))
{:ok, "/path/to/quiz.svg"}

Let’s try to decode the QR code above by your QR reader. You can find the result below…

Notes

  • this library was developed only for Byte mode
  • as side project was developed MatrixReloaded library for manipulating with matrices and vectors

Comments, what improve, what make better,.. are welcome.

Happy QR coding.

quiz_string =

Find what you love and let it kill you.
Charles Bukowski

First Post! Switch mode

ondrej-tucek

ondrej-tucek OP

QRCode v3.0.0 is out!

See news below:

Changed

  • The main usage is now simplified:

    # QRCode.create() has default :low error correction and :byte mode
    "your_string" 
    |> QRCode.create() 
    |> QRCode.render() 
    |> QRCode.save("/tmp/qr_code.svg")
    

    Instead of QRCode.save(), you can use a function QRCode.to_base64() to encode QR to base 64.

  • In SVG settings was changed the option :format with type :none or :indent on :structure with :minify (default value) or :readable for more clearer using. The variable :structure now reflects the structure of svg file. The final svg can be minified using by :minify or :readable and thus little bit larger.

Added

  • Alphanumeric mode, thank for mpichette contribution.

    # QRCode.render() has default :svg and SvgSettings
    "your_string" 
    |> QRCode.create(:low, :alphanumeric) 
    |> QRCode.render() 
    |> QRCode.save("/tmp/qr_code.svg")
    
  • Embedded image to svg. Support embedded image are only type: jpeg, jpg, png, or svg.

    # image = {".../path/to/name.type", size}, where size must be positive integer and means how embedded image will be large in the final svg file
    iex> alias QRCode.Render.SvgSettings
    iex> image = {"/docs/elixir.svg", 100}
    iex> qr_color = {17, 170, 136}
    iex> svg_settings = %SvgSettings{qrcode_color: qr_color, image: image, structure: :readable}
    %QRCode.Render.SvgSettings{
      background_color: "#ffffff",
      background_opacity: nil,
      image: {"/docs/elixir.svg", 100},
      qrcode_color: {17, 170, 136},
      scale: 10,
      structure: :readable
    }
    iex> "your_string"
          |> QRCode.create()
          |> QRCode.render(:svg, svg_settings)
          |> QRCode.save("/tmp/qr-with-image.svg")
      {:ok, "/tmp/qr-with-image.svg"}
    

  • Png render. You can save the QR to png file.

    # You can use PngSettings similar as above in QRCode.render(:svg) 
    ...
    |> QRCode.render(:png) 
    |> QRCode.save("/tmp/qr_code.png")
    

More information and examples will find on hex.pm or check the Github library.

— All posts loaded —

Where Next?

Trending in Announcing Top

bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
387 14960 120
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
shahryarjb
The Chelekom project is a library of Phoenix and LiveView components generated via Mix tasks to fit developer needs seamlessly. One of i...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

Other Trending Topics Top

type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
bjorng
We want to introduce a new native datatype to Erlang: native records. Although replacing all tuple records with native records is not our...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
alexslade
Fly’s CEO posted this recently - Turn And Face The Strange · The Fly Blog It says that Fly is going all-in on sprites, which is a worry ...
New

We're in Beta

About us Mission Statement