Help language development. Donate to The Perl Foundation
Image::QRCode - An interface to libqrencode.
Operating System | Build Status | CI Provider |
---|---|---|
Linux | Travis CI |
my $code = Image::QRCode.new.encode('https://perl6.org/'); my $dim = $code.qrcode.width; my @array2D[$dim;$dim] = $code.get-data(2); say @array2D.shape; say @array2D; my @array1D = $code.get-data(1); say @array1D;
use Image::QRCode; Image::QRCode.new.encode('https://perl6.org/').termplot;
For more examples see the example
directory.
Image::QRCode provides an interface to libqrencode and allows you to generate a QR Code.
Creates an Image::QRCode object. It may take a list of optional arguments.
The optional argument $version defaults to 0 (auto-select). The maximum version value is 4.
The optional argument $level defaults to QR_ECLEVEL_L
. The list of possible values for this argument is provided by the QRecLevel enum:
QR_ECLEVEL_L
# lowestQR_ECLEVEL_M
QR_ECLEVEL_Q
QR_ECLEVEL_H
# highestThe optional argument $mode defaults to QR_MODE_8
. The list of possible values for this argument is provided by the QRencodeMode enum:
QR_MODE_NUL
# Terminator (NUL character). Internal use onlyQR_MODE_NUM
# Numeric modeQR_MODE_AN
# Alphabet-numeric modeQR_MODE_8
# 8-bit data modeQR_MODE_KANJI
# Kanji (shift-jis) modeQR_MODE_STRUCTURE
# Internal use onlyQR_MODE_ECI
# ECI modeQR_MODE_FNC1FIRST
# FNC1, first positionQR_MODE_FNC1SECOND
# FNC1, second positionThe optional argument $casesensitive defaults to True.
The optional argument $size defaults to 2. This argument is used only when generating a character based plot of the QR code to adjust the relative proportion of width vs. height.
All these arguments can be accessed directly for both reading and writing:
my Image::QRCode $code .= new; $code.casesensitive = False;
Encodes a string. It takes one mandatory argument: text, the string to encode. All the other arguments are optional.
This method put a QR code in the attribute qrcode, an object of class QRcode, which can be read directly or managed by other methods.
The class QRcode is an interface to the library's internal structure of a QR code. It has three attributes:
Even if the data attribute can be accessed directly, its representation is a bit complex and most of the coded information is not very useful. The original library's documentation goes as follows:
Symbol data is represented as an array contains width*width uchars. Each uchar represents a module (dot). If the less significant bit of the uchar is 1, the corresponding module is black. The other bits are meaningless for usual applications, but here its specification is described. MSB 76543210 LSB |||||||`- 1=black/0=white ||||||`-- data and ecc code area |||||`--- format information ||||`---- version information |||`----- timing pattern ||`------ alignment pattern |`------- finder pattern and separator `-------- non-data modules (format, timing, etc.)
This method returns the QR code data, encoded as a 1D or 2D array. The argument dimension can be 1 or 2: passing a dimension = 1 the method returns a linear array of the values of all the dots, coded as 0 (black) or 1 (white). A value of 2 makes the method return an array of arrays.
This method accepts the optional parameter size, which determines the orizontal stretch of the "image". It prints the QR code on the terminal screen as \c[FULL BLOCK]
characters. It returns a Failure object if there's no data to plot.
This module provides an interface to all the C library's functions. The library's full documentation can be found here:
https://fukuchi.org/works/qrencode/manual/index.html
Its GitHub page is:
https://github.com/fukuchi/libqrencode
When using the low level calls, keep in mind that old versions of the library may lack some functionality:
This module requires the libqrencode4 library to be installed.
In case one has any API-compatible version, this module also reads the dynamically-assigned environment variable
PERL6_QRENCODE_LIB
. For example
PERL6_QRENCODE_LIB=libqrencode.so.3 ./program.p6
For the installation please follow the instructions below, based on your platform:
sudo apt-get install libqrencode4
To install it using zef (a module management tool):
$ zef update $ zef install Image::QRCode
To run the tests:
$ prove -e "perl6 -Ilib"
Image::QRCode relies on a C library which might not be present in one's installation, so it's not a substitute for a pure Perl6 module.
Fernando Santagata
The Artistic License 2.0