a barcode creation lib for golang

Join the chat at https://gitter.im/golang-barcode/Lobby

Introduction

This is a package for GO which can be used to create different types of barcodes.

Supported Barcode Types

  • 2 of 5
  • Aztec Code
  • Codabar
  • Code 128
  • Code 39
  • Code 93
  • Datamatrix
  • EAN 13
  • EAN 8
  • PDF 417
  • QR Code

Example

This is a simple example on how to create a QR-Code and write it to a png-file

package main

import (
	"image/png"
	"os"

	"github.com/boombuler/barcode"
	"github.com/boombuler/barcode/qr"
)

func main() {
	// Create the barcode
	qrCode, _ := qr.Encode("Hello World", qr.M, qr.Auto)

	// Scale the barcode to 200x200 pixels
	qrCode, _ = barcode.Scale(qrCode, 200, 200)

	// create the output file
	file, _ := os.Create("qrcode.png")
	defer file.Close()

	// encode the barcode as png
	png.Encode(file, qrCode)
}

Documentation

See GoDoc

To create a barcode use the Encode function from one of the subpackages.

Comments
  • Thank you for replying... but my question was unanswered

    Thank you for replying... but my question was unanswered

    Thank you for replying... but which one is correct?

    I am new to programming in Go... and could use a little help with this.... (thanks !)

    		bytes := []byte("hello world")
    		azCode, _ := aztec.Encode(bytes, aztec.DEFAULT_EC_PERCENT, aztec.DEFAULT_LAYERS)
    		azCode, _ = barcode.Scale(azCode, 40, 100)
    
    		retval := A or B 
    
                  return retval
    

    So how do I convert the barcode to a byte array?

    ( I don't need it in a PNG or other image type... I just need a byte string )

    A

    retval := []byte(azCode.Content())  // is this right????
    

    or

    B

    retval := []byte(azCode)
    
    // actually go has a problem with this:
    // cannot convert azCode (variable of type barcode.Barcode) to []bytecompilerInvalidConversion
    

    Originally posted by @MichaelLiss in https://github.com/boombuler/barcode/issues/66#issuecomment-871646780

  • Code 128A?

    Code 128A?

    I need to encode the string FNC3+"$P\rI", but encoding \r (carriage return) requires code 128A. Further investigation reveals this library only supports 128B and 128C. Any chance you could add 128A as well?

    (FNC3+"$P\rI" is a special code to begin/end programming Datalogic-brand barcode scanners)

  • UUID

    UUID

    Hi, I am trying to use uuid for barcode but every online validator shows resulting image as invalid. This generator produces valid uuid barcode according to this validator.

    From what I've gathered it has most likely something to do with the FNC1 character but I have no idea what. I tried to prefix the uuid with it but no success.

  • Unreadable code128 image

    Unreadable code128 image

    I use this code to generate image

    code, err := code128.EncodeWithoutChecksum("1234567890")
    ...
    code, err = barcode.Scale(code, 180, 90)
    ...
    err = png.Encode(w, code)
    

    (some lines are skipped) this is what I got in browser image image and the lower image was generated with web online generator. As you can see there is difference starting from line 19, which makes my barcode incorrect. I tried two different mobile scanners, both of them easily scan lower image but cannot recognize upper one.

    Do you have the same barcode for 1234567890?

  • Printer and reader

    Printer and reader

    This library looks just like what I need.

    I am planning to integrate it with a USB based bar code reader. Has anyone tried this yet ?

    Also reading via the camera on a phone. I can give it a go and submit a sample but wanted to check first it will be accepted ?

  • [Question] Genrating an GS1-128 barcode

    [Question] Genrating an GS1-128 barcode

    Hi!

    We're using you library to generate barcodes and so far it been working geat.

    However we've hit a road bump in generating a GS1-128 barcode (most likely we've missunderstood how the library works) when it comes to the hidden FNC1 character. Looking though the source it looks like you support this but it's a bit unclear to us how should generate this type of label.

    Are we supposed to send in the FNC1 character manually?

  • QR encode broken for L correction level

    QR encode broken for L correction level

    Hi, I've catched encoding bug with QR encoded with L error correction level. Data read by scanner has one byte different from original. Data is in base64, and code.Content() returns correct value, so error must be somewhere in rendering.

    I don't know QR algorithm internals well, and it could be possible that I simply have to increase error correction level, but I doubt it.

    Here is an example code with real value from production: http://play.golang.org/p/IWmXxzQzT3 (it will not work in playground, must be run locally)

  • Can I take parameters after the url?

    Can I take parameters after the url?

    qrCode, _ := qr.Encode('http://www.aa.com?a=123', qr.M, qr.Auto)

    Scan the QR code and open it with a browser. The request address becomes https://www.aa.com/?a=123

  • 144x144 datamatrix are not possible

    144x144 datamatrix are not possible

    When trying to create a datamatrix from a long text which would result in a 144x144 grid, the code crashes with an index out of range runtime error in /barcode_master/src/github.com/boombuler/barcode/datamatrix/errorcorrection.go:69

    As far as I can tell from the datamatrix specs, this type of grid has alternating block size and CWs.

  • Any way to get the checksum for code 128 barcodes?

    Any way to get the checksum for code 128 barcodes?

    I'm writing an application which generates barcodes for logistics labels and one of the requirements is that the checksum from code 128 subset C barcode is printed on the label. Is there any easy way to access that value using this library?

  • Error about Scale function

    Error about Scale function

    Hi I got an error when resize barcode which is can not scale barcode to an image smaller than 244x1,I paste the code as blow ` content:="hello code128"

    barcodePic, err := code128.Encode(content)

    if err != nil {
    
    	return  err
    
    }
    
    codePic, err := barcode.Scale(barcodePic, 200, 30)
    
    if err != nil {
    
    	return  err
    
    }
    
    file, err := os.Create("sample.png")
    
    if err != nil {
    
    	return err
    
    }
    
    defer file.Close()
    
    err = png.Encode(file, codePic)
    
    if err != nil {
    
    	return  err
    
    }
    

    ` Pls help to check it Thanks a lot

  • Datamatrix ECC200 16x48 with variable module size

    Datamatrix ECC200 16x48 with variable module size

    We have been using https://linux.die.net/man/1/dmtxwrite for a while but I'd like to use more this library.

    I'm reading the code and fiddling around to implement a 16x48 datamatrix with a module size of 5 pixels but I have some questions related to a low knowledge of the datamatrix spec and I hoped to receive some feedback.

    • What is the ECC Count? https://github.com/boombuler/barcode/blob/master/datamatrix/codesize.go#L8
    • Does the encodeText() needs to be changed or is the encoding the same also for rectangular datamatrix?

    I'd like to keep this ticket open for future questions and feedbacks as I learn the library and try to implement my changes, hopefully for a successful PR in the future.

  • Tests errors: runeint_test.go:7:3: Errorf format %d has arg string(IntToRune(0)) of wrong type string

    Tests errors: runeint_test.go:7:3: Errorf format %d has arg string(IntToRune(0)) of wrong type string

    The following errors are happening with Go 1.15 on Fedora Rawhide:

    github.com/boombuler/barcode/utils
    # github.com/boombuler/barcode/utils
    ./runeint_test.go:7:3: Errorf format %d has arg string(IntToRune(0)) of wrong type string
    ./runeint_test.go:16:3: Error call has possible formatting directive %d
    ./runeint_test.go:19:3: Error call has possible formatting directive %d
    ./runeint_test.go:22:3: Error call has possible formatting directive %d
    FAIL	github.com/boombuler/barcode/utils [build failed]
    
  • Does not allow for specifying an encoding

    Does not allow for specifying an encoding

    This library is only capable of encoding UTF-8 strings. Many external systems that read barcodes require specific encoding such as ISO-8859-1 or Shift_JIS. This is especially true of legacy hardware.

    The ability to specify the encoding of the string would make this library much more useful.

  • Does not allow encoding of binary data

    Does not allow encoding of binary data

    All methods take a string as an input. While raw data could. be base64 encoded. There are applications where barcodes contain a byte array. To the extent that the barcode protocol permits it, it should be possible to have a method that takes a byte array as an input and encodes raw binary data.

  • AZTEC siez limitation ?

    AZTEC siez limitation ?

    Hi, I think i found a strange limitation in the AZTEC barcode. When there is more than 472 chars in the barcode, it is not readable in 33% error code mode :

    ... cab2d := "lsdkfmlkfmlkmkmezlkfmlzkfkezfezmfkkljkljkljflmfkelmfklmfezlfkezlmfkzlmefkelfkezlmfezmlflemkflmfklzfelzkflmfkezlmfkezmlfkzefkemzlfkmlezkfmzelfkezmkfelzmfkelzmfkzelmfkezmlfkezlmkflemzfklmezfkelzmfkezmlkfezlfkelmzfkezlmfkezmfkezlmkflmezkfezlmfkezmlfkezmlfklmezkflemzfkzemlkflzmekflzemfkezlmkfezmlfkezlmfkezmlfkezflmkezmlfelmzkfelmzfkzekflemzfklmezfkflmezklmfkezlmfkezlmfkezlfkelzmfkelzmfkezmlfkezlmfkezlmfklzmefkmezlfklmezkflemzkfmlezkfmlezkfezflkzemflkzemlfkzelmfkmelzfkmlz"

    keyAztec := barcode.RegisterAztec(pdf, cab2d, 33, 0) barcode.Barcode(pdf, keyAztec, posX + 87.1, posY + 66.6, 28, 28, false) ...

    => the generated barcode is not readable. => if you delete one character and generate it again, it works again.

    Please tell me if i made a mistake.

    Thank you very much, excuse my poor english :).

OpenStreetMap PBF golang parser

pbf OpenStreetMap PBF golang encoder/decoder A golang based OpenStreetMap PBF encoder/decoder with a handy command line utility, pbf. pbf Command Line

Oct 23, 2022
golang OpenGL helper functions

glh: golang OpenGL helpers This package contains a number of functions useful for applications using OpenGL. Code Reference Features Textures and Text

Apr 8, 2022
A library for playing with colors in go (golang).
A library for playing with colors in go (golang).

go-colorful A library for playing with colors in Go. Supports Go 1.13 onwards. Why? I love games. I make games. I love detail and I get lost in detail

Dec 30, 2022
gumble is a Mumble client implementation in Go (golang)

gumble gumble is a Mumble client implementation in Go Sub-projects gumble (docs) Client library gumbleopenal (docs) OpenAL audio system for gumble gum

Jan 5, 2023
Rasterx is an SVG 2.0 path compliant rasterizer that can use either the golang vector or a derivative of the freetype anti-aliaser.
Rasterx is an SVG 2.0 path compliant rasterizer that can use either the golang vector or a derivative of the freetype anti-aliaser.

rasterx Rasterx is a golang rasterizer that implements path stroking functions capable of SVG 2.0 compliant 'arc' joins and explicit loop closing. Pat

Nov 1, 2022
Pure golang image resizing
Pure golang image resizing

This package is no longer being updated! Please look for alternatives if that bothers you. Resize Image resizing for the Go programming language with

Jan 9, 2023
:triangular_ruler: Create beautiful generative image patterns from a string in golang.
:triangular_ruler: Create beautiful generative image patterns from a string in golang.

geopattern Create beautiful generative image patterns from a string in golang. Go port of Jason Long's awesome GeoPattern library. Read geopattern's d

Dec 29, 2022
Pure Golang Library that allows simple LSB steganography on images
Pure Golang Library that allows simple LSB steganography on images

Steganography Lib Steganography is a library written in Pure go to allow simple LSB steganography on images. It is capable of both encoding and decodi

Dec 22, 2022
GameBoy Color emulator written in golang.
GameBoy Color emulator written in golang.

?? Worldwide 日本語のドキュメントはこちら GameBoyColor emulator written in golang. This emulator can play almost all ROMs work without problems and has many feature

Dec 26, 2022
A captcha library written in golang
A captcha library written in golang

gocaptcha 一个简单的Go语言实现的验证码 图片实例 简介 基于Golang实现的图片验证码生成库,可以实现随机字母个数,随机直线,随机噪点等。可以设置任意多字体,每个验证码随机选一种字体展示。 实例 使用: go get github.com/lifei6671/gocaptcha/

Dec 29, 2022
golang package to find the K most dominant/prominent colors in an image
golang package to find the K most dominant/prominent colors in an image

prominentcolor Find the K most dominant colors in an image The Kmeans function returns the K most dominant colors in the image, ordered in the order o

Nov 7, 2022
go chart is a basic charting library in native golang.
go chart is a basic charting library in native golang.

go-chart Package chart is a very simple golang native charting library that supports timeseries and continuous line charts. Master should now be on th

Dec 30, 2022
NanoVGo NanoVGNanoVGo is pure golang implementation of NanoVG. The same author maintains the NanoGUI.go project mentioned above.

NanoVGo Pure golang implementation of NanoVG. NanoVG is a vector graphics engine inspired by HTML5 Canvas API. DEMO API Reference See GoDoc Porting Me

Dec 6, 2022
使用 Golang+Chrome+OpenCV 破解腾讯滑块验证码
使用 Golang+Chrome+OpenCV 破解腾讯滑块验证码

一、背景 滑块验证码是一项人机识别技术,操作简单,真人体验好,机器识别效果也不差,可以有效防止脚本做任务,增加机器脚本薅羊毛的难度。但其破解也相对简单,这里演示一个Demo,以了解。通过 OpenCV 匹配找出滑块位置,计算出滑动距离,然后模拟 js 鼠标事件,在 Chrome 控制台执行脚本,完成

Dec 28, 2022
🔍 gowitness - a golang, web screenshot utility using Chrome Headless

?? gowitness A golang, web screenshot utility using Chrome Headless. introduction gowitness is a website screenshot utility written in Golang, that us

Jan 9, 2023
golang aspect tool
golang aspect tool

简介 go-aspect是一个为golang提供切面编程可能性的工具,可以使用该工具,替换原有的go build来进行编译,将预先配置好的切面编织到目标代码中 效果图 安装方式 源码安装 下载源码到本地 切换到源码目录,运行 make install 使用简介 目前仅支持mod模式的工程 编织是基于

Mar 13, 2022
An image server toolkit in Go (Golang)
An image server toolkit in Go (Golang)

Image Server An image server toolkit in Go (Golang) Features HTTP server Resize (GIFT, nfnt resize, Graphicsmagick) Rotate Crop Convert (JPEG, GIF (an

Dec 22, 2022
Golang implementation of the covid certificate QRCode decoder

Golang implementation of the covid certificates. At the moment it only includes DCC signed data decoding but I've planned to add a lot more of features related to certificates processing.

Sep 22, 2021
Use Windows API to capture a image from a Webcam in GoLANG

Windows-API-Capture-Webcam Use Windows API to capture a image from a Webcam in GoLANG Other Go is a amazing and powerful programming language. If you

Aug 13, 2022