ThierryO / qrcode

QRcode Generator for R
https://Thierryo.github.io/qrcode
GNU General Public License v3.0
42 stars 7 forks source link

Long QR codes not scannable #5

Closed smallworlnd closed 2 years ago

smallworlnd commented 3 years ago

Hello,

The example code on the main page creates an invalid/unreadable QR code from the long string.

library(qrcode)
inputString <- paste0(
  rep("abcdefghijklmnopqrstuvwxyz1234567890", 63), collapse = ""
)
qrcode_gen(inputString, softLimitFlag = FALSE)
ThierryO commented 3 years ago

I can confirm this is a bug. It occurs when the input string is longer dan 134 characters with the default error correction level.

character_set <- c(letters, LETTERS, rep(" ", 20), 0:9)
random_character <- sample(character_set, 134, replace = TRUE)
input_string <- paste(random_character, collapse = "")
random_character <- sample(character_set, 135, replace = TRUE)
input_string2 <- paste(random_character, collapse = "")
qrcode_gen(input_string)
qrcode_gen(input_string2)

It occurs with shorter strings when the error correction level increases.

qrcode_gen(input_string, ErrorCorrectionLevel = "M")
random_character <- sample(character_set, 107, replace = TRUE)
input_string3 <- paste(random_character, collapse = "")
qrcode_gen(input_string3, ErrorCorrectionLevel = "M")

I didn't wrote the main functions of the package. So it will take me some time to fix this.

ThierryO commented 2 years ago

This should be fixed. Can you please try the new version?

remotes::install_github("thierryo/qrcode@bugfix")
library(qrcode)
inputString <- paste0(
  rep("abcdefghijklmnopqrstuvwxyz1234567890", 63), collapse = ""
)
plot(qr_code(inputString))
smallworlnd commented 2 years ago

I had a hard time getting my QR code reader to recognise an image that complex, but at least a string 350 characters in length can now be properly encoded and recognised! Thanks!