Code Monkey home page Code Monkey logo

go-qrcode's Introduction

go-qrcode

Go Report Card go.dev reference Go GitHub release (latest SemVer) GitHub go.mod Go version License

QR code (abbreviated from Quick Response Code) is the trademark for a type of matrix barcode (or two-dimensional barcode) first designed in 1994 for the automotive industry in Japan. A barcode is a machine-readable optical label that contains information about the item to which it is attached. A QR code uses four standardized encoding modes (numeric, alphanumeric, byte/binary, and kanji) to store data efficiently; extensions may also be used

Features

  • Normally generate QR code across version 1 to version 40.
  • Automatically analyze QR version by source text.
  • Specifying cell shape allowably with WithCustomShape, WithCircleShape (default is rectangle)
  • Specifying output file's format with WithBuiltinImageEncoder, WithCustomImageEncoder (default is JPEG)
  • Not only shape of cell, but also color of QR Code background and foreground color.
  • WithLogoImage, WithLogoImageFilePNG, WithLogoImageFileJPEG help you add an icon at the central of QR Code.
  • WithBorderWidth allows to specify any width of 4 sides around the qrcode.
  • WebAssembly support, check out the Example and README for more detail.
  • support Halftone QR Codes, check out the Example.

Install

go get -u github.com/yeqown/go-qrcode/v2

Quick Start

link to CODE

package main

import (
	"github.com/yeqown/go-qrcode/v2"
	"github.com/yeqown/go-qrcode/writer/standard"
)

func main() {
	qrc, err := qrcode.New("https://github.com/yeqown/go-qrcode")
	if err != nil {
		fmt.Printf("could not generate QRCode: %v", err)
		return
	}
	
	w, err := standard.New("../assets/repo-qrcode.jpeg")
	if err != nil {
		fmt.Printf("standard.New failed: %v", err)
		return
	}
	
	// save file
	if err = qrc.Save(w); err != nil {
		fmt.Printf("could not save image: %v", err)
	}
}

Options

const (
	// EncModeNone mode ...
	EncModeNone encMode = 1 << iota
	// EncModeNumeric mode ...
	EncModeNumeric
	// EncModeAlphanumeric mode ...
	EncModeAlphanumeric
	// EncModeByte mode ...
	EncModeByte
	// EncModeJP mode ...
	EncModeJP
)

// WithEncodingMode sets the encoding mode.
func WithEncodingMode(mode encMode) EncodeOption {}

const (
	// ErrorCorrectionLow :Level L: 7% error recovery.
	ErrorCorrectionLow ecLevel = iota + 1
	
	// ErrorCorrectionMedium :Level M: 15% error recovery. Good default choice.
	ErrorCorrectionMedium
	
	// ErrorCorrectionQuart :Level Q: 25% error recovery.
	ErrorCorrectionQuart
	
	// ErrorCorrectionHighest :Level H: 30% error recovery.
	ErrorCorrectionHighest
)

// WithErrorCorrectionLevel sets the error correction level.
func WithErrorCorrectionLevel(ecLevel ecLevel) EncodeOption {}

following are some shots:


Built-in Writers

Of course, you can also code your own writer, just implement Writer interface.

Migrating from v1

go-qrcode.v2 is a major upgrade from v1, and it is not backward compatible. v2 redesigned the API, and it is more flexible and powerful. Features are split into different modules (according to functionality).

  • github.com/yeqown/go-qrcode/v2 core
  • github.com/yeqown/go-qrcode/writer/standard writer/imageFile
  • github.com/yeqown/go-qrcode/writer/terminal writer/terminal

Check example/migrating-from-v1 for more details.

Links

go-qrcode's People

Contributors

yeqown avatar dependabot[bot] avatar orefalo avatar buckeyecoder avatar arajhansa avatar fionera avatar mnrtks avatar mikedunk avatar vedantmadane avatar yeung66 avatar vsvp21 avatar eeddaann avatar h44z avatar roamboy avatar sausheong avatar user1121114685 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.