Code Monkey home page Code Monkey logo

barcode's Introduction

Barcode Package

The Barcode Package is a simple yet powerful library written in Golang designed to handle barcode generation and decoding. This package provides functionalities to generate a 13-number barcode string, create barcode images, and decode barcode information from images.

Features

  • Generate 13-digit barcode strings
  • Encode barcode strings into images
  • Decode barcode images to retrieve information

Installation

To install the Barcode Package, use go get:

go get github.com/myrachanto/barcode

Usage

First, import the package in your Go file:

import "github.com/myrachanto/barcode"

Generate Barcode String

The GenerateBarCodeNumber method generates a random 13-digit barcode string.

barcodeString := barcode.GenerateBarCodeNumber()
fmt.Println("Generated Barcode String:", barcodeString)

Encode Barcode String to Image

The Encode method encodes a 13-digit barcode string into an image and saves it as a PNG file.

barcodeString := barcode.GenerateBarCodeNumber()
err := barcode.Encode(barcodeString, "barcode_image")
if err != nil {
    // handle error
    fmt.Println("Error:", err)
} else {
    fmt.Println("Barcode image created successfully")
}

Decode Barcode Image

The Decode method reads a barcode image and returns the encoded information.

decodedString, err := barcode.Decode("barcode_image")
if err != nil {
    // handle error
    fmt.Println("Error:", err)
} else {
    fmt.Println("Decoded Barcode String:", decodedString)
}

Methods

GenerateBarCodeNumber

Generates a random 13-digit barcode string.

Signature:

func GenerateBarCodeNumber() string

Encode

Encodes a 13-digit barcode string into an image and saves it as a PNG file.

Signature:

func Encode(msg, filename string) error

Parameters:

  • msg (string): The 13-digit barcode string to encode.
  • filename (string): The name of the file (without extension) to save the barcode image.

Returns:

  • error: An error if the encoding or file creation fails, otherwise nil.

Decode

Reads a barcode image and decodes it into a string.

Signature:

func Decode(filename string) (string, error)

Parameters:

  • filename (string): The name of the file (without extension) to read the barcode image from.

Returns:

  • string: The decoded barcode string.
  • error: An error if the decoding or file reading fails, otherwise nil.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any changes.

Acknowledgments

  • Inspired by various open-source barcode libraries.
  • Special thanks to the Golang community for their support and contributions.

barcode's People

Contributors

myrachanto avatar

Stargazers

Kevin S. Clarke avatar oraz avatar Echo avatar Jahongir Temirov avatar Kirill Trunov avatar

Watchers

 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.