From f6d969ccbd0458e99809fbaf28b652cde48e300f Mon Sep 17 00:00:00 2001 From: rex <1073853456@qq.com> Date: Sun, 6 Nov 2022 15:16:27 +0800 Subject: [PATCH] fix bug for pixels with large values --- Project.toml | 2 +- README.md | 2 +- src/QRCoders.jl | 14 ++++++++------ test/tst_construct.jl | 6 ++++++ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Project.toml b/Project.toml index e4e4b4f..c05639f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "QRCoders" uuid = "f42e9828-16f3-11ed-2883-9126170b272d" authors = ["Jérémie Gillet and contributors"] -version = "1.3.0" +version = "1.3.1" [deps] FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" diff --git a/README.md b/README.md index 1b000ec..668d4db 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ A file will be saved at `./qrcode.png`. > ![QRCode1](https://cdn.jsdelivr.net/gh/juliaimages/QRCoders.jl@assets/qrcode.png) ### QRCode struct -`QRCode` is a data type that contains the data of a QR Code. +`QRCode` is a structure type that contains the data of a QR Code. ```jl julia> code = QRCode("Hello world!") diff --git a/src/QRCoders.jl b/src/QRCoders.jl index 401df6b..f8f6c00 100644 --- a/src/QRCoders.jl +++ b/src/QRCoders.jl @@ -4,7 +4,7 @@ Module that can create QR codes as data or images using `qrcode` or `exportqrcod module QRCoders # create QR code -export qrcode, exportqrcode, QRCode +export qrcode, exportqrcode, exportbitmat, QRCode # supported modes export Mode, Numeric, Alphanumeric, Byte, Kanji, UTF8 @@ -278,7 +278,7 @@ function exportbitmat( matrix::BitMatrix n = size(matrix, 1) pixels = ceil(Int, 72 * targetsize / 2.45 / n) * n end - save(path, BitArray(.! _resize(matrix, pixels))) + save(path, .! _resize(matrix, pixels)) end """ @@ -392,7 +392,6 @@ function exportqrcode( codes::AbstractVector{QRCode} , fps::Int = 2) # all equal valid only in Julia 1.8+ length(unique!(qrwidth.(codes))) == 1 || throw(EncodeError("The codes should have the same size")) - targetwidth = qrwidth(first(codes)) # check whether the image format is supported if !endswith(path, r"\.\w+") path *= ".gif" @@ -402,15 +401,18 @@ function exportqrcode( codes::AbstractVector{QRCode} "$ext\n is not a valid format for animated images")) end # generate frames + matwidth = qrwidth(first(codes)) if targetsize > 0 # original keyword -- will be removed in the future - pixels = ceil(Int, 72 * targetsize / 2.45 / targetwidth) * targetwidth + Base.depwarn("keyword `targetsize` will be removed in the future, use `pixels` instead", :exportbitmat) + pixels = ceil(Int, 72 * targetsize / 2.45 / matwidth) * matwidth + else + pixels = ceil(Int, pixels / matwidth) * matwidth end - pixels = pixels ÷ targetwidth * targetwidth code = Array{Bool}(undef, pixels, pixels, length(codes)) for (i, c) in enumerate(codes) code[:,:,i] = _resize(qrcode(c), pixels) end - save(path, BitArray(.! code), fps=fps) + save(path, .! code, fps=fps) end """ diff --git a/test/tst_construct.jl b/test/tst_construct.jl index 5352b11..c63abc7 100644 --- a/test/tst_construct.jl +++ b/test/tst_construct.jl @@ -185,6 +185,12 @@ end exportqrcode(msgs, imgpath * "qrcode-瀚文茗荷.gif", fps=2) @test true + # large image + msgs = [join(rand('0':'9', 5596)) for _ in 1:5]; + codes = QRCode.(msgs, version=40, width=4); + exportqrcode(codes, "qrcodes.gif") + @test true + # test failed exportqrcode(msgs, imgpath * "qrcode-瀚文茗荷", fps=2) # no extension @test_throws EncodeError exportqrcode(msgs, imgpath * "qrcode-瀚文茗荷.jpg", fps=2) # invalid extension