A command line tool and library written in Go to generate QR Codes with logos/images embedded. The logos can be padded in different ways to make them stand out.
- Go needs to be installed then the following command can be used to add qrlogo to your project:
go get -u github.com/alexandernorth/qrlogo
- Import
qrlogo
into your code:
import "github.com/alexandernorth/qrlogo"
Create a file with the following contents:
package main
import (
"os"
"path"
"github.com/alexandernorth/qrlogo"
)
func main() {
logo, err := qrlogo.OpenImage("logo.png")
if err != nil {
panic(err)
}
qlg := qrlogo.NewQRLogo(logo)
qrLogo, err := qlg.QRCodeForURL("https://github.com/alexandernorth/qrlogo")
if err != nil {
panic(err)
}
outputDir := "qrcodes"
err = os.MkdirAll(outputDir, 0755)
if err != nil {
panic(err)
}
err = qrlogo.SaveToPNGFile(qrLogo, path.Join(outputDir, "qr.png"))
if err != nil {
panic(err)
}
}
QRLogo can be configured with several options:
Sets the background color of the code
qlg := qrlogo.NewQRLogo(
logo,
qrlogo.BackgroundColor(colornames.Map["white"]),
)
Sets the colour of the QRCode bars
qlg := qrlogo.NewQRLogo(
logo,
qrlogo.CodeColour(colornames.Map["black"]),
)
Sets whether there is a border around the whole QRCode
qlg := qrlogo.NewQRLogo(
logo,
qrlogo.DisableBorder(false),
)
Sets the percentage of the QRCode to be covered in range [0,1] with 1 being 100%. The error correction ability of a QRCode is at max 30%, so this value should not be exceeded, but other factors may force this value down
qlg := qrlogo.NewQRLogo(
logo,
qrlogo.LogoCoverage(0.2),
)
Sets the type of padding to use when rendering the logo.
Valid options are:
- dilate
- none
- square
- circle
qlg := qrlogo.NewQRLogo(
logo,
qrlogo.PaddingType(qrlogo.LogoPaddingDilate),
)
LogoPaddingType
is a string, so it is also possible to specify the type through a string:
qlg := qrlogo.NewQRLogo(
logo,
qrlogo.PaddingType(qrlogo.LogoPaddingType("dilate")),
)
Sets the amount of padding around the logo
qlg := qrlogo.NewQRLogo(
logo,
qrlogo.PaddingWeight(20),
)
Sets the size of the output image
qlg := qrlogo.NewQRLogo(
logo,
qrlogo.QRSize(2048),
)