Title: | Generate QRcodes with R |
---|---|
Description: | Create static QR codes in R. The content of the QR code is exactly what the user defines. We don't add a redirect URL, making it impossible for us to track the usage of the QR code. This allows to generate fast, free to use and privacy friendly QR codes. |
Authors: | Thierry Onkelinx [aut, cre] (Author of the reimplemented functions, <https://orcid.org/0000-0001-8804-4216>), Victor Teh [aut] (Original author) |
Maintainer: | Thierry Onkelinx <[email protected]> |
License: | GPL-3 |
Version: | 0.3.0 |
Built: | 2025-01-27 05:10:59 UTC |
Source: | https://github.com/ThierryO/qrcode |
First generate a qr_code
with a higher ecl
level.
Then add the logo.
The maximum area of logo depends on the difference in ecl
level between the
version with and without logo.
The size of the logo is further restricted by its image ratio.
We shrink very wide or tall logos to make sure it still fits on the logo.
add_logo( code, logo, ecl = c("L", "M", "Q", "H"), hjust = c("c", "l", "r"), vjust = c("c", "b", "t") )
add_logo( code, logo, ecl = c("L", "M", "Q", "H"), hjust = c("c", "l", "r"), vjust = c("c", "b", "t") )
code |
A |
logo |
the path to a logo image file.
Must be either |
ecl |
the required error correction level for the QR code
after overlaying the logo.
Must be lower than the |
hjust |
Horizontal position of the logo.
The default of |
vjust |
Vertical position of the logo.
The default of |
Convert a bits object into a character string
## S3 method for class 'bits' as.character(x, ...)
## S3 method for class 'bits' as.character(x, ...)
x |
the bits object |
... |
currently ignore |
Thierry Onkelinx
Other bits:
bits()
,
bits2int()
,
c.bits()
,
print.bits()
z <- bits(c(FALSE, TRUE, TRUE, FALSE)) z as.character(z)
z <- bits(c(FALSE, TRUE, TRUE, FALSE)) z as.character(z)
Converts a logical vector into a bits object.
This remains a logical vector.
The main difference is that is printed as a 0
and 1
bit string rather
than a FALSE
and TRUE
vector
bits(x)
bits(x)
x |
a logical vector |
Thierry Onkelinx
Other bits:
as.character.bits()
,
bits2int()
,
c.bits()
,
print.bits()
z <- bits(c(FALSE, TRUE)) z str(z)
z <- bits(c(FALSE, TRUE)) z str(z)
Convert a bits object to an integer and vice versa
bits2int(x) int2bits(i, n_bit = 16)
bits2int(x) int2bits(i, n_bit = 16)
x |
the bits object |
i |
the integer |
n_bit |
the number of bits |
Thierry Onkelinx
Other bits:
as.character.bits()
,
bits()
,
c.bits()
,
print.bits()
z <- bits(c(FALSE, TRUE, TRUE, FALSE)) z y <- bits2int(z) y int2bits(y) int2bits(y, 4)
z <- bits(c(FALSE, TRUE, TRUE, FALSE)) z y <- bits2int(z) y int2bits(y) int2bits(y, 4)
The result inherits arguments from the first element.
## S3 method for class 'bits' c(...)
## S3 method for class 'bits' c(...)
... |
the bits to concatenate |
Thierry Onkelinx
Other bits:
as.character.bits()
,
bits()
,
bits2int()
,
print.bits()
z <- bits(c(FALSE, TRUE)) z c(z, z, rev(z))
z <- bits(c(FALSE, TRUE)) z c(z, z, rev(z))
Selects the dark elements from the qr_code
object and returns their
coordinates.
This can be useful when you want to create a QR code with a custom style.
coordinates(x)
coordinates(x)
x |
the |
A data.frame
with the column
and row
number of the dark
elements.
Thierry Onkelinx
Other qr:
generate_svg()
,
plot.qr_code()
,
print.qr_code()
,
qr_code()
,
qr_event()
,
qr_location()
,
qr_sepa()
,
qr_wifi()
x <- qr_code("test") plot(x) head(coordinates(x)) plot(coordinates(x), pch = 19, cex = 2, asp = 1)
x <- qr_code("test") plot(x) head(coordinates(x)) plot(coordinates(x), pch = 19, cex = 2, asp = 1)
Create the QR code using qr_code()
and save it as an svg file.
generate_svg( qrcode, filename, size = 300, foreground = "black", background = "white", show = interactive(), ... ) ## Default S3 method: generate_svg( qrcode, filename, size = 300, foreground = "black", background = "white", show = interactive(), ... ) ## S3 method for class 'qr_code' generate_svg( qrcode, filename, size = 300, foreground = "black", background = "white", show = interactive(), ... ) ## S3 method for class 'qr_wifi' generate_svg( qrcode, filename, size = 300, foreground = "black", background = "white", show = interactive(), ..., fontsize = 15 ) ## S3 method for class 'qr_logo' generate_svg( qrcode, filename, size = 300, foreground = "black", background = "white", show = interactive(), ... )
generate_svg( qrcode, filename, size = 300, foreground = "black", background = "white", show = interactive(), ... ) ## Default S3 method: generate_svg( qrcode, filename, size = 300, foreground = "black", background = "white", show = interactive(), ... ) ## S3 method for class 'qr_code' generate_svg( qrcode, filename, size = 300, foreground = "black", background = "white", show = interactive(), ... ) ## S3 method for class 'qr_wifi' generate_svg( qrcode, filename, size = 300, foreground = "black", background = "white", show = interactive(), ..., fontsize = 15 ) ## S3 method for class 'qr_logo' generate_svg( qrcode, filename, size = 300, foreground = "black", background = "white", show = interactive(), ... )
qrcode |
a |
filename |
Where to store the QR code as svg file. Silently overwrites existing files. Tries to create the path, when it doesn't exist. |
size |
width of the svg file in pixels.
Defaults to |
foreground |
Stroke and fill colour for the foreground.
Use a valid CSS colour.
Defaults to |
background |
Fill colour for the background.
Use a valid CSS colour.
Defaults to |
show |
Open the file after creating it.
Defaults to |
... |
Currently ignored. |
fontsize |
The size of the font in pixels. |
invisible NULL
Thierry Onkelinx
Other qr:
coordinates()
,
plot.qr_code()
,
print.qr_code()
,
qr_code()
,
qr_event()
,
qr_location()
,
qr_sepa()
,
qr_wifi()
code <- qr_code("HELLO WORLD") generate_svg( qrcode = code, filename = tempfile(fileext = ".svg"), show = FALSE )
code <- qr_code("HELLO WORLD") generate_svg( qrcode = code, filename = tempfile(fileext = ".svg"), show = FALSE )
Plot the QR code This function plots to QR code to the open device.
## S3 method for class 'qr_code' plot(x, col = c("white", "black"), y, ...) ## S3 method for class 'qr_logo' plot(x, col = c("white", "black"), y, ...)
## S3 method for class 'qr_code' plot(x, col = c("white", "black"), y, ...) ## S3 method for class 'qr_logo' plot(x, col = c("white", "black"), y, ...)
x |
the |
col |
Define the colours.
The first element refers to |
y |
currently ignored |
... |
currently ignored |
Thierry Onkelinx
opencv::ocv_qr_detect()
for reading QR codes.
Other qr:
coordinates()
,
generate_svg()
,
print.qr_code()
,
qr_code()
,
qr_event()
,
qr_location()
,
qr_sepa()
,
qr_wifi()
Other qr:
coordinates()
,
generate_svg()
,
print.qr_code()
,
qr_code()
,
qr_event()
,
qr_location()
,
qr_sepa()
,
qr_wifi()
qr <- qr_code("HELLO WORLD") plot(qr) # Test the QR code with the opencv package if (requireNamespace("opencv")) { png("test.png") plot(qr) dev.off() opencv::ocv_qr_detect(opencv::ocv_read('test.png')) unlink("test.png") }
qr <- qr_code("HELLO WORLD") plot(qr) # Test the QR code with the opencv package if (requireNamespace("opencv")) { png("test.png") plot(qr) dev.off() opencv::ocv_qr_detect(opencv::ocv_read('test.png')) unlink("test.png") }
FALSE
is shown as 0
and
TRUE
as 1
.Print a bits vector
Display the logical vector as a bit string where FALSE
is shown as 0
and
TRUE
as 1
.
## S3 method for class 'bits' print(x, ...)
## S3 method for class 'bits' print(x, ...)
x |
the object to print |
... |
currently ignored |
Thierry Onkelinx
Other bits:
as.character.bits()
,
bits()
,
bits2int()
,
c.bits()
z <- bits(c(FALSE, TRUE)) print(z)
z <- bits(c(FALSE, TRUE)) print(z)
Please use plot(x)
for a better quality image
## S3 method for class 'qr_code' print(x, ...)
## S3 method for class 'qr_code' print(x, ...)
x |
the |
... |
currently ignored |
Thierry Onkelinx
Other qr:
coordinates()
,
generate_svg()
,
plot.qr_code()
,
qr_code()
,
qr_event()
,
qr_location()
,
qr_sepa()
,
qr_wifi()
qr_code("HELLO WORLD")
qr_code("HELLO WORLD")
A QR code is a two-dimensional barcode developed by the Denso Wave company.
qr_code(x, ecl = c("L", "M", "Q", "H"))
qr_code(x, ecl = c("L", "M", "Q", "H"))
x |
the input string |
ecl |
the required error correction level.
Available options are |
The QR code as a logical matrix with "qr_code" class.
Thierry Onkelinx
Other qr:
coordinates()
,
generate_svg()
,
plot.qr_code()
,
print.qr_code()
,
qr_event()
,
qr_location()
,
qr_sepa()
,
qr_wifi()
qr_code("https://www.r-project.org") qr <- qr_code("https://cran.r-project.org/package=qrcode", ecl = "M") qr plot(qr) # the qr_code object is a logical matrix str(qr) qr[1:10, 1:10]
qr_code("https://www.r-project.org") qr <- qr_code("https://cran.r-project.org/package=qrcode", ecl = "M") qr plot(qr) # the qr_code object is a logical matrix str(qr) qr[1:10, 1:10]
The message converted into a bit string.
qr_encode(x, ecl = c("L", "M", "Q", "H"))
qr_encode(x, ecl = c("L", "M", "Q", "H"))
x |
the input string |
ecl |
the required error correction level.
Available options are |
Thierry Onkelinx
Other internal:
qr_error()
,
qr_matrix()
,
qr_mode()
,
qr_version()
qr_encode("HELLO WORLD")
qr_encode("HELLO WORLD")
The function returns a bit string containing the message.
qr_error(x, ecl = c("L", "M", "Q", "H"))
qr_error(x, ecl = c("L", "M", "Q", "H"))
x |
the input string |
ecl |
the required error correction level.
Available options are |
The message as a bits()
object.
Thierry Onkelinx
Other internal:
qr_encode()
,
qr_matrix()
,
qr_mode()
,
qr_version()
qr_error("HELLO WORLD")
qr_error("HELLO WORLD")
Generate a QR code for an event
qr_event(start, end, title, ..., ecl = c("L", "M", "Q", "H"))
qr_event(start, end, title, ..., ecl = c("L", "M", "Q", "H"))
start |
the required start time as |
end |
the required end time as |
title |
the required title of the event. |
... |
optional arguments as defined in the details. |
ecl |
the required error correction level.
Available options are |
Optional arguments. Other arguments are silently ignored.
description
location
organiser
url
Other qr:
coordinates()
,
generate_svg()
,
plot.qr_code()
,
print.qr_code()
,
qr_code()
,
qr_location()
,
qr_sepa()
,
qr_wifi()
Create a QR code for a location
qr_location(latitude, longitude, ecl = c("L", "M", "Q", "H"))
qr_location(latitude, longitude, ecl = c("L", "M", "Q", "H"))
latitude |
the latitude of the location. |
longitude |
the longitude of the location. |
ecl |
the required error correction level.
Available options are |
Other qr:
coordinates()
,
generate_svg()
,
plot.qr_code()
,
print.qr_code()
,
qr_code()
,
qr_event()
,
qr_sepa()
,
qr_wifi()
qr_location(50.8449861, 4.3499932) |> plot()
qr_location(50.8449861, 4.3499932) |> plot()
Prepare matrices with default patterns and unmasked data A list with a matrix containing the default patterns (finder pattern, timing pattern, separators, alignment pattern and dark module), the unmask data pattern and the version.
qr_matrix(x, ecl = c("L", "M", "Q", "H"))
qr_matrix(x, ecl = c("L", "M", "Q", "H"))
x |
the input string |
ecl |
the required error correction level.
Available options are |
Thierry Onkelinx
Other internal:
qr_encode()
,
qr_error()
,
qr_mode()
,
qr_version()
qr_matrix("HELLO WORLD")
qr_matrix("HELLO WORLD")
The current implementation handles three modes: numeric, alphanumeric and
byte.
Kanji is currently not supported.
Please contact the maintainer if you need it.
Numeric: only digits from 0 to 9
Alphanumeric: all numeric characters, upper case LETTERS
, and the
characters " "
(space), "$"
, "%"
, "*"
, "+"
, "-"
, "."
, "/"
and
":"
Byte: All characters from the Latin 1 (ISO 8859-1) character set.
Input strings with an other encoding are converted into Latin 1.
The function return an error if such conversion fails.
qr_mode(x)
qr_mode(x)
x |
the input string |
a character indicating the mode
Thierry Onkelinx
Other internal:
qr_encode()
,
qr_error()
,
qr_matrix()
,
qr_version()
qr_mode("0123") qr_mode("A") qr_mode("a")
qr_mode("0123") qr_mode("A") qr_mode("a")
Generate a QR code for a SEPA payment
qr_sepa( iban, beneficiary, amount, unstructured_reference = "", bic = "", purpose = "", structured_reference = "" )
qr_sepa( iban, beneficiary, amount, unstructured_reference = "", bic = "", purpose = "", structured_reference = "" )
iban |
the IBAN of the beneficiary. |
beneficiary |
the name of the beneficiary. |
amount |
the amount to transfer. Must be in EUR. |
unstructured_reference |
the unstructured reference. The unstructured reference is a string of maximum 140 characters. |
bic |
the BIC of the beneficiary. |
purpose |
the purpose of the payment. |
structured_reference |
the structured reference. |
Other qr:
coordinates()
,
generate_svg()
,
plot.qr_code()
,
print.qr_code()
,
qr_code()
,
qr_event()
,
qr_location()
,
qr_wifi()
qr_sepa( iban = "GB33BUKB20201555555555", beneficiary = "John Doe", amount = 100, unstructured_reference = "Test payment" ) |> plot()
qr_sepa( iban = "GB33BUKB20201555555555", beneficiary = "John Doe", amount = 100, unstructured_reference = "Test payment" ) |> plot()
Create a QR code for a vCard
qr_vcard( given, family, address, email, telephone, organisation, job_title, url, gender, logo, photo, middle = character(0), prefix = character(0), suffix = character(0), ecl = c("L", "M", "Q", "H"), ... )
qr_vcard( given, family, address, email, telephone, organisation, job_title, url, gender, logo, photo, middle = character(0), prefix = character(0), suffix = character(0), ecl = c("L", "M", "Q", "H"), ... )
given |
The given name. |
family |
The family name. |
address |
In case of a single address, a named character vector with
the following elements: |
email |
Optionally one or more email addresses. The names of the vector are used as the type of the email address. |
telephone |
Optionally one of more telephone numbers. The names of the vector are used as the type of the telephone number. |
organisation |
Optionally the name of your organisation and team within the organisation. |
job_title |
Optionally the job title of the person. |
url |
Optionally one or more URLs. The names of the vector are used as the type of the URL. |
gender |
Optionally a string describing the gender of the person. |
logo |
Optionally a URL to a logo. |
photo |
Optionally a URL to a photo. |
middle |
Optionally one or more middle names. |
prefix |
Optionally one or more prefixes. |
suffix |
Optionally one or more suffixes. |
ecl |
the required error correction level.
Available options are |
... |
Additional arguments are silently ignored. |
Determine the required version Returns a list with the version, error correction level and mode. The bit string encodes mode and the length of the input string.
qr_version(x, ecl = c("L", "M", "Q", "H"))
qr_version(x, ecl = c("L", "M", "Q", "H"))
x |
the input string |
ecl |
the required error correction level.
Available options are |
Thierry Onkelinx
Other internal:
qr_encode()
,
qr_error()
,
qr_matrix()
,
qr_mode()
qr_version("HELLO WORLD") qr_version("hello world", ecl = "H")
qr_version("HELLO WORLD") qr_version("hello world", ecl = "H")
Generate QR code with wifi login information
qr_wifi( ssid, encryption = c("WPA", "WEP", ""), key = "", hidden = FALSE, ecl = c("L", "M", "Q", "H") )
qr_wifi( ssid, encryption = c("WPA", "WEP", ""), key = "", hidden = FALSE, ecl = c("L", "M", "Q", "H") )
ssid |
The SSID of the network. |
encryption |
The encryption standard.
Options are |
key |
The key for the encryption. |
Use |
|
ecl |
the required error correction level.
Available options are |
Other qr:
coordinates()
,
generate_svg()
,
plot.qr_code()
,
print.qr_code()
,
qr_code()
,
qr_event()
,
qr_location()
,
qr_sepa()