standard

package module
v0.0.0-...-50532fe Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2022 License: MIT Imports: 12 Imported by: 0

README

Standard Writer

go.dev reference

Standard Writer is a writer that is used to draw QR Code image into io.Writer, normally a file.

Usage

options := []ImageOption{
	WithBgColorRGBHex("#ffffff"),
	WithFgColorRGBHex("#000000"),
	// more ...
}

// New will create file automatically.
writer, err := standard.New("filename", options...)

// or use io.WriteCloser
var w io.WriterCloser
writer2, err := standard.NewWith(w, options...)

Options

// WithBgTransparent makes the background transparent.
func WithBgTransparent() ImageOption {}

// WithBgColor background color
func WithBgColor(c color.Color) ImageOption {}

// WithBgColorRGBHex background color
func WithBgColorRGBHex(hex string) ImageOption {}

// WithFgColor QR color
func WithFgColor(c color.Color) ImageOption {}

// WithFgColorRGBHex Hex string to set QR Color
func WithFgColorRGBHex(hex string) ImageOption {}

// WithLogoImage .
func WithLogoImage(img image.Image) ImageOption {}

// WithLogoImageFilePNG load image from file, PNG is required
func WithLogoImageFilePNG(f string) ImageOption {}

// WithLogoImageFileJPEG load image from file, JPEG is required
func WithLogoImageFileJPEG(f string) ImageOption {}

// WithQRWidth specify width of each qr block
func WithQRWidth(width uint8) ImageOption {}

// WithCircleShape use circle shape as rectangle(default)
func WithCircleShape() ImageOption {}

// WithCustomShape use custom shape as rectangle(default)
func WithCustomShape(shape IShape) ImageOption {}

// WithBuiltinImageEncoder option includes: JPEG_FORMAT as default, PNG_FORMAT.
// This works like WithBuiltinImageEncoder, the different between them is
// formatTyp is enumerated in (JPEG_FORMAT, PNG_FORMAT)
func WithBuiltinImageEncoder(format formatTyp) ImageOption

// WithCustomImageEncoder to use custom image encoder to encode image.Image into
// io.Writer
func WithCustomImageEncoder(encoder ImageEncoder) ImageOption

// WithBorderWidth specify the both 4 sides' border width. Notice that
// WithBorderWidth(a) means all border width use this variable `a`,
// WithBorderWidth(a, b) mean top/bottom equal to `a`, left/right equal to `b`.
// WithBorderWidth(a, b, c, d) mean top, right, bottom, left.
func WithBorderWidth(widths ...int) ImageOption

// WithHalftone ...
func WithHalftone(path string) ImageOption

extension

Documentation

Index

Constants

View Source
const (
	// JPEG_FORMAT as default output file format.
	JPEG_FORMAT formatTyp = iota
	// PNG_FORMAT .
	PNG_FORMAT
)

Variables

View Source
var (
	ErrNilWriter = errors.New("nil writer")
)

Functions

This section is empty.

Types

type Attribute

type Attribute struct {
	// width and height of image
	W, H int
	// in the order of "top, right, bottom, left"
	Borders [4]int
	// the length of  block edges
	BlockWidth int
}

Attribute contains basic information of generated image.

type DrawContext

type DrawContext struct {
	*gg.Context
	// contains filtered or unexported fields
}

DrawContext is a rectangle area

func (*DrawContext) Color

func (dc *DrawContext) Color() color.Color

Color returns the color which should be fill into the shape. Note that if you're not using this color but your coded color.Color, some ImageOption functions those set foreground color would take no effect.

func (*DrawContext) Edge

func (dc *DrawContext) Edge() (width, height int)

Edge returns width and height of each shape could take at most.

func (*DrawContext) UpperLeft

func (dc *DrawContext) UpperLeft() (dx, dy float64)

UpperLeft returns the point which indicates the upper left position.

type IShape

type IShape interface {
	// Draw the shape of QRCode block in IShape implemented way.
	Draw(ctx *DrawContext)

	// DrawFinder to fill the finder pattern of QRCode, what's finder? google it for more information.
	DrawFinder(ctx *DrawContext)
}

type ImageEncoder

type ImageEncoder interface {
	// Encode specify which format to encode image into io.Writer.
	Encode(w io.Writer, img image.Image) error
}

ImageEncoder is an interface which describes the rule how to encode image.Image into io.Writer

type ImageOption

type ImageOption interface {
	// contains filtered or unexported methods
}

func WithBgColor

func WithBgColor(c color.Color) ImageOption

WithBgColor background color

func WithBgColorRGBHex

func WithBgColorRGBHex(hex string) ImageOption

WithBgColorRGBHex background color

func WithBgTransparent

func WithBgTransparent() ImageOption

WithBgTransparent makes the background transparent.

func WithBorderWidth

func WithBorderWidth(widths ...int) ImageOption

WithBorderWidth specify the both 4 sides' border width. Notice that WithBorderWidth(a) means all border width use this variable `a`, WithBorderWidth(a, b) mean top/bottom equal to `a`, left/right equal to `b`. WithBorderWidth(a, b, c, d) mean top, right, bottom, left.

func WithBuiltinImageEncoder

func WithBuiltinImageEncoder(format formatTyp) ImageOption

WithBuiltinImageEncoder option includes: JPEG_FORMAT as default, PNG_FORMAT. This works like WithBuiltinImageEncoder, the different between them is formatTyp is enumerated in (JPEG_FORMAT, PNG_FORMAT)

func WithCircleShape

func WithCircleShape() ImageOption

WithCircleShape use circle shape as rectangle(default)

func WithCustomImageEncoder

func WithCustomImageEncoder(encoder ImageEncoder) ImageOption

WithCustomImageEncoder to use custom image encoder to encode image.Image into io.Writer

func WithCustomShape

func WithCustomShape(shape IShape) ImageOption

WithCustomShape use custom shape as rectangle(default)

func WithFgColor

func WithFgColor(c color.Color) ImageOption

WithFgColor QR color

func WithFgColorRGBHex

func WithFgColorRGBHex(hex string) ImageOption

WithFgColorRGBHex Hex string to set QR Color

func WithHalftone

func WithHalftone(path string) ImageOption

WithHalftone ...

func WithLogoImage

func WithLogoImage(img image.Image) ImageOption

WithLogoImage image should only has 1/5 width of QRCode at most

func WithLogoImageFileJPEG

func WithLogoImageFileJPEG(f string) ImageOption

WithLogoImageFileJPEG load image from file, jpeg is required. image should only have 1/5 width of QRCode at most

func WithLogoImageFilePNG

func WithLogoImageFilePNG(f string) ImageOption

WithLogoImageFilePNG load image from file, PNG is required. image should only have 1/5 width of QRCode at most

func WithLogoSizeMultiplier

func WithLogoSizeMultiplier(multiplier int) ImageOption

WithLogoSizeMultiplier used in Writer in validLogoImage method to validate logo size

func WithQRWidth

func WithQRWidth(width uint8) ImageOption

WithQRWidth specify width of each qr block

type Writer

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

Writer is a writer that writes QR Code to io.Writer.

func New

func New(filename string, opts ...ImageOption) (*Writer, error)

New creates a standard writer.

func NewWithWriter

func NewWithWriter(writeCloser io.WriteCloser, opts ...ImageOption) *Writer

func (Writer) Attribute

func (w Writer) Attribute(dimension int) *Attribute

func (Writer) Close

func (w Writer) Close() error

func (Writer) Write

func (w Writer) Write(mat qrcode.Matrix) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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