2023-09-01 20:50:47 +01:00
|
|
|
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"
|
2023-09-01 21:51:30 +01:00
|
|
|
"git.fjla.uk/fred.boniface/barcodes/web"
|
2023-09-01 20:50:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2023-09-01 21:51:30 +01:00
|
|
|
web.StartServer()
|
|
|
|
|
2023-09-01 20:50:47 +01:00
|
|
|
}
|