Skip to content

Commit

Permalink
Merge pull request #35 from RexWzh/QRCode
Browse files Browse the repository at this point in the history
New structure type QRCode
  • Loading branch information
RexWzh authored Nov 5, 2022
2 parents 9838275 + 7b60e86 commit 47ebaf8
Show file tree
Hide file tree
Showing 8 changed files with 554 additions and 189 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.2.2"
version = "1.3.0"

[deps]
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Expand Down
55 changes: 28 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,23 @@ julia> qrcode("Hello world!")

The value `1(true)` represents a dark space and `0(false)` a white square.

### Unicode Plot
Method 1, as mentioned in [issue#25](https://github.com/JuliaImages/QRCoders.jl/issues/25).
### Export a QR Code as a file

Exporting files is also easy.

```julia
julia> exportqrcode("Hello world!")
```

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.

```jl
julia> unicodeplotbychar("Hello world!") |> print
julia> code = QRCode("Hello world!")
█████████████████████████
██ ▄▄▄▄▄ █▀ █ ▄█ ▄▄▄▄▄ ██
██ █ █ █▄ █▀▄█ █ █ ██
Expand All @@ -47,18 +59,20 @@ julia> unicodeplotbychar("Hello world!") |> print
██ █▄▄▄█ █▀ █▄▀▀█▄█▄█▄██
██▄▄▄▄▄▄▄█▄█▄▄▄██▄█▄█▄███
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
julia> exportqrcode(code)
```

Method 2, Unicode plot by [UnicodePlots.jl](https://github.com/JuliaPlots/UnicodePlots.jl).
Animated QR code is supported in version 1.3+.

```julia
julia> unicodeplot("Hello world!")
```jl
julia> exportqrcode(["Hello world!", "Hello Julia!"], fps=2)
```
<img src="https://cdn.jsdelivr.net/gh/juliaimages/QRCoders.jl@assets/unicodeplot.png" width="100">

Note: method 2 dosen't work for text strings.
> ![QRCode2](https://cdn.jsdelivr.net/gh/juliaimages/QRCoders.jl@assets/hellojulia.gif)
### Optional Parameters
The keyword `fps` controls the frame rate of the animation.

### Parameters

There are some optional arguments.

Expand All @@ -78,7 +92,7 @@ julia> qrcode("Hello world!", width=1)

The QR Code will be surrounded by a white border of width `width`.

Keywords `eclevel`, `version`, `mode` and `mask`:
Keywords `eclevel`, `version`, `mode` and `mask` in `qrcode`:

1. Error correction level `eclevel` can be picked from four values `Low()`, `Medium()`, `Quartile()` or `High()`. Higher levels make denser QR codes.

Expand All @@ -88,26 +102,13 @@ Keywords `eclevel`, `version`, `mode` and `mask`:

4. Mask pattern `mask` can be picked from 0 to 7. If the assigned `mask` is not valid, it will be picked automatically.


### Export a QR Code as a PNG/JPG file

Exporting files is also easy.

```julia
julia> exportqrcode("Hello world!")
```

A file will be saved at `./qrcode.png`.

> ![QRCode1](https://cdn.jsdelivr.net/gh/juliaimages/QRCoders.jl@assets/qrcode.png)
The keywords in `qrcode` are also available in `exportqrcode`. Moreover, a new keyword `targetsize` is used to control the size of the exported file.
Keywords in `qrcode` are also available in `exportqrcode`. Moreover, a new keyword `pixels` is used to control the size of the exported image.

```julia
julia> exportqrcode("Hello world!", "img/hello.png", targetsize = 10, width = 0)
julia> exportqrcode("Hello world!", "img/hello.png", pixels = 160, width = 0)
```

This file will be saved as `./img/hello.png` (if the `img` directory already exists), have a size of (approximately) 10 centimeters and be compact. Please note that compact codes may be hard to read depending on their background.
This file will be saved as `./img/hello.png` (if the `img` directory already exists), have a size of (approximately) 160 centimeters and be compact.

> ![QRCode2](https://cdn.jsdelivr.net/gh/juliaimages/QRCoders.jl@assets/hello.png)
Expand Down Expand Up @@ -143,7 +144,7 @@ julia> exportqrcode(join(Char.(0x80:0x9f)))

The original repository [QRCode.jl](https://github.com/JuliaImages/QRCode.jl) was created during the [Efficient Scientific Computing with Julia](https://groups.oist.jp/grad/skill-pill-67) workshop, taught by [Valentin Churavy](https://github.com/vchuravy) at the [Okinawa Institute of Science and Technology](https://www.oist.jp) in July 2019. [Slides available here](https://github.com/JuliaLabs/Workshop-OIST).

The current version QRCoders.jl(v1.0.0) is proposed as part of the [OSPP'2022 project](https://summer-ospp.ac.cn/).
The current version QRCoders.jl(v1.0.0) is proposed as part of the [OSPP'2022 project](https://summer-ospp.ac.cn/).

<!-- URLS -->

Expand Down
Binary file added docs/src/assets/qrcode-masks.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Module that can create QR codes as data or images using `qrcode` or `exportqrcod
```@docs
qrcode
exportqrcode
QRCode
```

## styled QR codes
Expand Down Expand Up @@ -40,3 +41,44 @@ Medium
Quartile
High
```

# Examples

Create a QR code matrix.

```julia
julia> using QRCoders

julia> qrcode("Hello world!")
21×21 BitMatrix:
1 1 1 1 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 1 1
1 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 1
1 0 1 1 1 0 1 0 0 0 1 1 0 0 1 0 1 1 1 0 1
1 0 1 1 1 0 1 0 1 0 0 0 1 0 0 1 0 0 1 0 0
1 0 0 0 0 0 1 0 0 1 0 1 0 1 1 1 1 0 0 0 1
1 1 1 1 1 1 1 0 1 0 1 1 0 1 1 1 0 0 1 0 0
```

Export a QR code image from message.

```julia
julia> exportqrcode("Hello world!")
```

A file will be saved at `./qrcode.png`.

> ![QRCode1](https://cdn.jsdelivr.net/gh/juliaimages/QRCoders.jl@assets/qrcode.png)
Create a `.gif` file from messages.

```julia
julia> # QR codes with different masks
julia> using QRCoders: penalty
julia> codes = [QRCode("Hello world!", mask = i) for i in 0:7]
julia> qrcode.(codes) .|> penalty |> print
[425, 485, 342, 318, 495, 562, 368, 415]
julia> exportqrcode(codes, fps=3)
```

> ![QRCode-masks](https://cdn.jsdelivr.net/gh/juliaimages/QRCoders.jl/docs/src/assets/qrcode-masks.gif)
Loading

2 comments on commit 47ebaf8

@RexWzh
Copy link
Member Author

@RexWzh RexWzh commented on 47ebaf8 Nov 5, 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/71689

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.0 -m "<description of version>" 47ebaf851e3a60b3bbc819f605f281f301aec306
git push origin v1.3.0

Please sign in to comment.