50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"image/png"
|
|
"os"
|
|
|
|
"github.com/boombuler/barcode"
|
|
|
|
"git.fjla.uk/fred.boniface/barcodes/generation"
|
|
"git.fjla.uk/fred.boniface/barcodes/validation"
|
|
)
|
|
|
|
func main() {
|
|
barcodeType := flag.String("type", "", "Barcode type (aztec, codabar, code93, code128, qr)")
|
|
content := flag.String("content", "", "Barcode content")
|
|
|
|
flag.Parse()
|
|
|
|
if *barcodeType == "" || *content == "" {
|
|
fmt.Println("Usage: ./barcodes --type <barcode_type> --content <content>")
|
|
return
|
|
}
|
|
|
|
fmt.Printf("Barcode Type: %s\n", *barcodeType)
|
|
fmt.Printf("Barcode Content: %s\n", *content)
|
|
|
|
validation.Validate(*content, *barcodeType)
|
|
|
|
parameters := generation.Parameters{
|
|
Format: generation.BarcodeType(*barcodeType),
|
|
ECCLevel: generation.ECCLevel(3),
|
|
Content: *content,
|
|
}
|
|
|
|
generated_barcode, err := generation.Generate(parameters)
|
|
if err != nil {
|
|
fmt.Println("Error: ", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
generated_barcode, _ = barcode.Scale(generated_barcode, 200, 200)
|
|
|
|
file, _ := os.Create("barcode.png")
|
|
defer file.Close()
|
|
png.Encode(file, generated_barcode)
|
|
|
|
}
|