qart

package module
v0.0.0-...-0cfdec6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2018 License: MIT Imports: 15 Imported by: 0

README

Qart

Build Status godoc

Package qart implements a QR Code encoder, basing on go-qrcode, with other funny features.

Install

There are two ways to get executable file.

  1. Download the executable file in project's releases or qart/bin folder.

  2. Build yourself.

    go get -u github.com/xrlin/qart/...
    

    A command-line tool qart will be built into $GOPATH/bin/.

CLI

# create code with png
qart -m test.png -o out.png http://example.com

# create code with specified area of png
qart -m test.png -startX 100 -startY 100 -width 100 -oout.png http://example.com

# overlay code on source image
qart -m test.png -startX 100 -startY 100 -width 100 -embed true -o out.gif http://example.com

# create code with gif
qart -m illya.gif -o out.png http://example.com

More options can found by

qart -h

Usage

import "github.com/xrlin/qart"

q, err := qrcode.NewHalftoneCode(content, qrcode.Highest)
q.AddOption(qart.Option{Embed: false, MaskImagePath: "test.png"})
pointWidth := 3
// Get the image.Image represents the qr code
ret := q.CodeImage(pointWidth)

// Get the bytes of image
imgBytes, err := q.ImageData(pointWidth)

Read the godoc for more usages.

DemoApp

https://xrlin.github.io/qart-web

Examples

example example example

example

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HalftoneQRCode

type HalftoneQRCode struct {
	// Original content encoded.
	Content string

	// QR Code type.
	Level RecoveryLevel

	// QR Code version number
	VersionNumber int
	// contains filtered or unexported fields
}

HalftoneQRCode specify the basic qrcode and another options to generate a qrcode with image

func NewHalftoneCode

func NewHalftoneCode(content string, level RecoveryLevel) (*HalftoneQRCode, error)

NewHalftoneCode constructs a basic QRCode.

var q *cmd.HalftoneQRCode
q, err := cmd.NewHalftoneCode("my content", cmd.Medium)

An error occurs if the content is too long.

func (*HalftoneQRCode) AddOption

func (q *HalftoneQRCode) AddOption(cfg Option) *HalftoneQRCode

AddOption add Option to a HalftoneQRCode. Attention: only the none-zero field will be merged into HalftoneQRCode's option. If you want to delete an option, use RemoveOption method.

func (*HalftoneQRCode) Bitmap

func (q *HalftoneQRCode) Bitmap() [][]bool

Bitmap returns the QR Code as a 2D array of 1-bit pixels.

bitmap[y][x] is true if the pixel at (x, y) is set.

The bitmap includes the required "quiet zone" around the QR Code to aid decoding.

func (*HalftoneQRCode) CodeGif

func (q *HalftoneQRCode) CodeGif(pointWidth int) (ret *gif.GIF, err error)

CodeGif generates the code as a gif. pointWidth parameter set the width of a qr code module.

func (*HalftoneQRCode) CodeImage

func (q *HalftoneQRCode) CodeImage(pointWidth int) (ret image.Image, err error)

CodeImage generate the code as a normal image. pointWidth parameter set the width of a qr code module.

func (*HalftoneQRCode) ImageData

func (q *HalftoneQRCode) ImageData(pointWidth int) (ret []byte, err error)

ImageData generate code and return the bytes represents the cod image(png/gif). pointWidth parameter set the width of a qr code module.

func (HalftoneQRCode) Option

func (q HalftoneQRCode) Option() *Option

Option method returns the pointer point to option.

func (*HalftoneQRCode) RemoveOption

func (q *HalftoneQRCode) RemoveOption(opt OptionKey) *HalftoneQRCode

RemoveOption method set the option field's value to its zero value.

func (*HalftoneQRCode) ToString

func (q *HalftoneQRCode) ToString() string

ToString produces a multi-line string that forms a QR-code image. This method return the pure qrcode without mask image.

type HalftoneRegularSymbol

type HalftoneRegularSymbol struct {
	// contains filtered or unexported fields
}

type HalftoneSymbol

type HalftoneSymbol struct {
	// contains filtered or unexported fields
}

type Option

type Option struct {
	// User settable drawing options.
	ForegroundColor color.Color
	BackgroundColor color.Color

	MaskImagePath string
	MaskImageFile io.Reader

	MaskRectangle image.Rectangle

	Embed bool
}

Option struct contains the option to build code

type OptionKey

type OptionKey string

OptionKey act as the key of Option struct

const (
	// Field name of ForegroundColor in Option
	ForegroundColorOpt OptionKey = "ForegroundColor"
	// Field name of BackgroundColor in Option
	BackgroundColorOpt OptionKey = "BackgroundColor"
	// Field name of MaskImagePath in Option
	MaskImagePathOpt OptionKey = "MaskImagePath"
	// Field name of MaskImageFile in Option
	MaskImageFileOpt OptionKey = "MaskImageFile"
	// Field name of MaskRectangle in Option
	MaskRectangleOpt OptionKey = "MaskRectangle"
	// Field name of Embed in Option
	EmbedOpt OptionKey = "Embed"
)

type RecoveryLevel

type RecoveryLevel int

Error detection/recovery capacity.

There are several levels of error detection/recovery capacity. Higher levels of error recovery are able to correct more errors, with the trade-off of increased symbol size.

const (
	// Level L: 7% error recovery.
	Low RecoveryLevel = iota

	// Level M: 15% error recovery. Good default choice.
	Medium

	// Level Q: 25% error recovery.
	High

	// Level H: 30% error recovery.
	Highest
)

Directories

Path Synopsis
Package bitset implements an append only bit array.
Package bitset implements an append only bit array.
Package reedsolomon provides error correction encoding for QR Code 2005.
Package reedsolomon provides error correction encoding for QR Code 2005.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL