Skip to content

QRCode implements by Go (According to ISO/ECI 18004-2015 Standard). The QRCode Generator, Micro QRCode Generator, QRCode Decoder, Micro QRCode Decoder application.

License

Notifications You must be signed in to change notification settings

KangSpace/gqrcode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QR Code(Quick Response Code) Implement by Go

The QRCode Generator, Micro QRCode Generator, QRCode Decoder, Micro QRCode Decoder application.

According to ISO/IEC 18004-2015 Standard

Installation

go get -u github.com/KangSpace/gqrcode

Dependencies Package:

  1. imaging

go get -u github.com/disintegration/imaging

  1. image

mkdir $GOPATH/golang.org/x/
cd $GOPATH/golang.org/x/
git clone https://github.com/golang/image.git

  1. text

cd $GOPATH/golang.org/x/
git clone https://github.com/golang/text.git

Usage

QR Code

QRCode supports 4 character modes, and 40 versions with 4 Error correction levels.

Micro QRCode supports 4 character modes, and 4 versions with 4 Error correction levels.

4 Modes:

  • numeric
    characters(10): 0 - 9

    maximum characters in Version 40-L: 7089 characters.

  • alphanumeric
    characters(45): 0 - 9, A - Z, SP, $, %, *, +, -, ., /, :

    maximum characters in Version 40-L: 4296 characters.

    Alphanumeric mode is not available in Version M1 Micro QR Code Symbol

  • byte
    8-bit characters.

    maximum characters in Version 40-L: 2953 characters.

    Byte mode is not available in Version M1 or M2 Micro QR Code Symbol.

  • kanji
    Kanji characters in accordance with the Shift JIS system based on JIS X 0209. Only use for double-byte characters, Range are: \x8140-\x9FFC and \xE040-\xEBBF.

    maximum characters in Version 40-L: 2953 characters.

    Kanji mode is not available in Version M1 Or M2 Micro QR Code Symbol.

4 Error correction level:
Four levels of Reed-Solomon error correction(referred to as L, M, Q and H in increasing order of capacity) allowing recover of:

  • L 7%
  • M 15%
  • Q 25%
  • H 30%

    Micro QR Code is not support H level.

Create QR Code
    // create a numeric qrcode
    data := "0123456"
    qrcode, err := NewQRCode(data)   
    outFileName := "/opt/temp/numeric.png"
    if err == nil{
        // set color for qrcode
        // out := output.NewOutput(&output.BaseOutput{Type: output.PNG, Size: 400, CodeColor: output.ColorfulCodeColor})
        out := output.NewPNGOutput0()
        qrcode.Encode(out,outFileName)
    }
    
    // create a numeric micro qrcode
    micQrcode, err := NewMicroQRCode(data)   
    outFileName2 := "/opt/temp/numeric_micro.png"
    if err == nil{
        out2 := output.NewPNGOutput0()
        micQrcode.Encode(out2,outFileName2)
    }
Encode QR Code
   out := output.NewPNGOutput0()
   qrcode.Encode(out,outFileName)

Encode Params:

Parameter Type Values Comments
out output.Output NewPNGOutput(size int), NewPNGOutput0(), NewJPGOutput(size int), NewJPGOutput0(), NewGIFOutput(size int), NewGIFOutput0() Newxxx0() output with auto-size for image.
fileName string output file path -
Output QRCode

output.ImageOutput implements output.Output interface to output PNG,JPG,GIF image.

    out := output.NewPNGOutput(100)
    out = output.NewPNGOutput0()
  
    logoImageFilePath := "logo.png"
    // add logo image into QRCode
    out.AddOption(output.LogoOption(logoImageFilePath))

Output Params:

Parameter Type Values Comments
size int the image size for output -

Test QR Code

All QRCode test in qrcode_test.go and micro_qrcode_test.go files.

TODO list

Type Item Done Time
QRCode Model2 Numeric Mode and test 2021-05-30 22:47:57
Alphanumeric Mode 2021-05-31
Byte Mode 2021-05-31
Kanji Mode 2021-06-01
ECI Mode NOT-IMPLEMENT
FNC1 Mode NOT-IMPLEMENT
Mixed Mode NOT-IMPLEMENT
Structured Append Mode NOT-IMPLEMENT
QRCode Model1 - NOT-SUPPORT
Micro QRCode Micro QRCode 2021-06-07
Personalized QRCode
(add logo image at center of QRCode)
- 2021-06-02
Output Image File
(With Color)
2021-05-30
(2022-09-17)
Base64 String 2021-06-01
SVG -
Decoder QRCode -
Micro QRCode -

附录:

  1. Best size of QR code of each version. (1 point by 4 pixels!)
Version None QuietZone 1xQuietZone 2xQuietZone 4xQuietZone maxCharacterLen(AlphaNumeric,L)
1 84 92 100 116 25
2 100 108 116 132 47
3 116 124 132 148 77
4 132 140 148 164 114
5 148 156 164 180 154
6 164 172 180 196 195
7 180 188 196 212 224
8 196 204 212 228 279
9 212 220 228 244 335
10 228 236 244 260 395
11 244 252 260 276 468
12 260 268 276 292 535
13 276 284 292 308 619
14 292 300 308 324 667
15 308 316 324 340 758
16 324 332 340 356 854
17 340 348 356 372 938
18 356 364 372 388 1046
19 372 380 388 404 1153
20 388 396 404 420 1249
21 404 412 420 436 1352
22 420 428 436 452 1460
23 436 444 452 468 1588
24 452 460 468 484 1704
25 468 476 484 500 1853
26 484 492 500 516 1990
27 500 508 516 532 2132
28 516 524 532 548 2223
29 532 540 548 564 2369
30 548 556 564 580 2520
31 564 572 580 596 2677
32 580 588 596 612 2840
33 596 604 612 628 3009
34 612 620 628 644 3183
35 628 636 644 660 3351
36 644 652 660 676 3537
37 660 668 676 692 3729
38 676 684 692 708 3927
39 692 700 708 724 4087
40 708 716 724 740 4296
M1 44 52 60 76 5(Numeric)
M2 52 60 68 84 6
M3 60 68 76 92 14
M4 68 76 84 100 21

About

QRCode implements by Go (According to ISO/ECI 18004-2015 Standard). The QRCode Generator, Micro QRCode Generator, QRCode Decoder, Micro QRCode Decoder application.

Topics

Resources

License

Stars

Watchers

Forks

Languages