QR Code encoding and rendering.
Error correction level. Provides the following error correction capability:
Transform a string into a result Error
or a QRCode using Quartile ErrorCorrection.
Transform a string with a given ErrorCorrection into a result Error or a QRCode.
Transform a QRCode into a svg element.
qrCodeView : String -> Html msg
qrCodeView message =
QRCode.encode message
|> Result.map QRCode.toSvg
|> Result.withDefault
(Html.text "Error while encoding to QRCode.")Tip: You can determine the size of the generated svg setting
width and height styles.
Same as toSvg, but without the quiet zone.
Transform a QRCode into a string.
"Hello World!"
|> QRCode.encode
|> Result.map QRCode.toString
|> Result.withDefault "Error while encoding to QRCode."Returns:
■■■■■■■ ■■■■ ■■■■■■■
■ ■ ■■■■ ■ ■
■ ■■■ ■ ■■■■■ ■ ■■■ ■
■ ■■■ ■ ■ ■ ■ ■■■ ■
■ ■■■ ■ ■■■■ ■ ■■■ ■
■ ■ ■ ■ ■
■■■■■■■ ■ ■ ■ ■■■■■■■
■ ■■
■■ ■ ■■ ■ ■ ■■■■■
■■ ■■■ ■■■■ ■■■ ■■
■ ■■ ■■ ■■■■■ ■■■■■■
■■ ■■■■ ■ ■
■ ■ ■■■ ■■■■ ■■
■■ ■■■ ■■
■■■■■■■ ■ ■ ■■ ■■■
■ ■ ■ ■ ■ ■
■ ■■■ ■ ■■■ ■
■ ■■■ ■ ■■ ■■■ ■■
■ ■■■ ■ ■ ■ ■ ■ ■ ■ ■
■ ■ ■ ■ ■ ■
■■■■■■■ ■■■ ■ ■■Transform a QRCode into an Image. You can transform the Image into a PNG or BMP.
import Html
import Html.Attribute
import Image
import QRCode
viewQRCode : String -> Html msg
viewQRCode message =
QRCode.encode message
|> Result.map
(\qrCode ->
Html.img
[ QRCode.toImage qrCode
|> Image.toPngUrl
|> Html.Attribute.src
]
[]
)
|> Result.withDefault
(Html.text "Error while encoding to QRCode.")Note: You must install the justgook/elm-image package in order to use the functions to convert the Image type to something else:
elm install "justgook/elm-image"Transform a QRCode into an Image with an ImageOptions.
Available options to transform a QRCode into an Image with toImageWithOptions.
moduleSize is the size of the module (the dark square) in px;moduleColor and emptyColor expects an Int as 0xRRGGBBAA;quietZoneSize is the number of modules the quiet zone should have.Default options used by toImage.
defaultImageOptions =
{ moduleSize = 5
, moduleColor = 0xFF
, emptyColor = 0xFFFFFFFF
, quietZoneSize = 4
}Transform a QRCode into a list of list of booleans.
"Hello World!"
|> QRCode.encode
|> Result.map QRCode.toMatrix
|> Result.withDefault "Error while encoding to QRCode."Possible encoding errors.
QRCode type.