Skip to content

Commit

Permalink
Merge pull request #36 from RexWzh/QRCode
Browse files Browse the repository at this point in the history
fix bug for pixels
  • Loading branch information
RexWzh authored Nov 6, 2022
2 parents 47ebaf8 + f6d969c commit 10b5721
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "QRCoders"
uuid = "f42e9828-16f3-11ed-2883-9126170b272d"
authors = ["Jérémie Gillet <[email protected]> and contributors"]
version = "1.3.0"
version = "1.3.1"

[deps]
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
Expand Down
14 changes: 8 additions & 6 deletions src/QRCoders.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

"""
Expand Down Expand Up @@ -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"
Expand All @@ -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

"""
Expand Down
6 changes: 6 additions & 0 deletions test/tst_construct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

2 comments on commit 10b5721

@RexWzh
Copy link
Member Author

@RexWzh RexWzh commented on 10b5721 Nov 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/71739

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.3.1 -m "<description of version>" 10b57214b4b2a6ba7ccbbd387ea88319a20f4496
git push origin v1.3.1

Please sign in to comment.