bundle swiss cross image file to avoid file system dependency

This commit is contained in:
Michael Stapelberg
2020-06-20 11:31:00 +02:00
parent aceddb388b
commit f94dc9efc6
4 changed files with 203 additions and 10 deletions

View File

@@ -1,9 +1,9 @@
package qrbill
import (
"bytes"
"image"
"image/draw"
"os"
"github.com/boombuler/barcode"
"github.com/boombuler/barcode/qr"
@@ -50,15 +50,8 @@ func generateQrCodeImage(payload string) (image.Image, error) {
}
func overlayWithSwissCross(qrCodeImage image.Image) (image.Image, error) {
// TODO: bundle the swiss cross image instead of reading it
const swissCrossPath = "/home/michael/go/src/github.com/stapelberg/qrbill/third_party/swiss-cross/CH-Kreuz_7mm/CH-Kreuz_7mm.png"
f, err := os.Open(swissCrossPath)
if err != nil {
return nil, err
}
defer f.Close()
swissCrossImage, _, err := image.Decode(f)
b := swisscross["third_party/swiss-cross/CH-Kreuz_7mm/CH-Kreuz_7mm.png"]
swissCrossImage, _, err := image.Decode(bytes.NewReader(b))
if err != nil {
return nil, err
}