Skip to contents

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.

Usage

qr_code(link, file, logo = NULL, frame = NULL, offset = "+50+50")

Arguments

A character string containing the link to encode.

file

A character string indicating the path to the output file.

(optional) A character string indicating the path to a logo image file.

frame

(optional) A character string indicating the path to a frame file.

offset

(optional) A character string indicating the offset for positioning the QR code within the frame. See image_composite() to learn more.

Value

An invisible NULL. This function is called for its side effects.

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()