qr_code() creates a QR code from a given link and saves it as a
PNG file.
The QR code has a fixed size: 500 px without a frame, and 450 px when a frame is included.
Arguments
- link
A
characterstring containing the link to encode.- file
A
characterstring indicating the path to the output file.- logo
(optional) A
characterstring indicating the path to a logo image file.- frame
(optional) A
characterstring indicating the path to a frame file.- offset
(optional) A
characterstring indicating the offset for positioning the QR code within the frame. Seeimage_composite()to learn more.
Examples
library(ggplot2)
library(magick)
#> Linking to ImageMagick 6.9.12.98
#> Enabled features: fontconfig, freetype, fftw, heic, lcms, pango, raw, webp, x11
#> Disabled features: cairo, ghostscript, rsvg
#> Using 4 threads
link <- "https://github.com/danielvartan"
file <- tempfile(fileext = ".png")
# A Simple QR Code -----
qr_code(link = link, file = file)
file |>
image_read() |>
image_ggplot()
#> Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
#> ℹ Please use tidy evaluation idioms with `aes()`.
#> ℹ See also `vignette("ggplot2-in-packages")` for more information.
#> ℹ The deprecated feature was likely used in the magick package.
#> Please report the issue at <https://github.com/ropensci/magick/issues>.
# QR Code + Logo -----
qr_code(
link = link,
file = file,
logo = raw_data_1("github-icon.svg", "rutils")
)
file |>
image_read() |>
image_ggplot()
# QR Code + Logo + Frame -----
qr_code(
link = "https://github.com/danielvartan",
file = file,
logo = raw_data_1("github-icon.svg", "rutils"),
frame = raw_data_1("qr-code-frame.svg", "rutils")
)
file |>
image_read() |>
image_ggplot()
