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

Most Liked

ondrej-tucek

ondrej-tucek

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.

Where Next?

Popular in Announcing Top

danschultzer
In short Plug n’ play OAuth 2.0 provider library. Just set up a resource owner schema with Ecto (your user schema), install the dependen...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
985 42920 311
New
Crowdhailer
The latest release of Ace (0.10.0) includes serving content over HTTP/2. I have started writing a webserver to teach my self more about...
New
tfwright
After working on it for a couple of months and using it in production for most of that time, today I’ve released LiveAdmin, a LiveView ba...
New
devonestes
Introducing assertions, the library that helps you write really great test assertions! GitHub: GitHub - devonestes/assertions: Helpful a...
New
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...
384 13736 119
New
blatyo
The best overview for how things are tied together is this presentation. Modules and functions are pretty well documented at this point, ...
New
fuelen
Hey folks! Want to present a toolkit for writing command-line user interfaces. It provides a convenient interface for colorizing text...
New
michalmuskala
Hello everybody. I have just released Jason - a new JSON library. You might be wondering, why do we need a new library? The primary foc...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement