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…
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
18 Likes
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.
8 Likes