added assets.go

This commit is contained in:
Raum0x2A
2021-05-06 11:21:35 -06:00
parent 877517b923
commit d6bfa643a9
4 changed files with 1132 additions and 25 deletions

1050
assets.go Normal file

File diff suppressed because one or more lines are too long

View File

@@ -3,6 +3,7 @@ package nmslib
import ( import (
"fmt" "fmt"
"image/png" "image/png"
"io/ioutil"
"os" "os"
"strconv" "strconv"
@@ -29,6 +30,13 @@ func CreateBanner(portalhex string, savename string, opt int) {
var vert int var vert int
var horz int var horz int
// Setup temp dir
tempdir, err := ioutil.TempDir("", "nmslib-")
if err != nil {
panic(err)
}
//defer os.RemoveAll(tempdir)
// verify len of portalhex // verify len of portalhex
if len(portalhex) == 12 { if len(portalhex) == 12 {
// get hex value from each digit in given string to an array of int64 // get hex value from each digit in given string to an array of int64
@@ -56,30 +64,47 @@ func CreateBanner(portalhex string, savename string, opt int) {
// assign image location of its glyph hex value to an array of strings // assign image location of its glyph hex value to an array of strings
for j := 0; j < len(glyphImg); j++ { for j := 0; j < len(glyphImg); j++ {
glyphImg[j] = fmt.Sprintf("./assets/glyphs/%s/PORTALSYMBOL.%X.png", mode, GlyphHex[j]) glyphImg[j] = fmt.Sprintf("assets/glyphs/%s/PORTALSYMBOL.%X.png", mode, GlyphHex[j])
}
// pull images need from glyph.go and saved them to ./glyphs/
for k := 0; k < len(glyphImg); k++ {
data, err := Asset(glyphImg[k])
if err != nil {
panic(err)
}
_, err2 := os.Stat(tempdir + "/assets/glyphs/" + mode + "/")
if os.IsNotExist(err2) {
errDir := os.MkdirAll(tempdir+"/assets/glyphs/"+mode, 0755)
if errDir != nil {
panic(errDir)
}
}
fmt.Println(tempdir + "/" + glyphImg[k])
err = ioutil.WriteFile(tempdir+"/"+glyphImg[k], []byte(data), 0644)
}
// load images for processing using github.com/ozankasikci/go-image-merge
grids := []*gim.Grid{
{ImageFilePath: tempdir + "/" + glyphImg[0]}, {ImageFilePath: tempdir + "/" + glyphImg[1]},
{ImageFilePath: tempdir + "/" + glyphImg[2]}, {ImageFilePath: tempdir + "/" + glyphImg[3]},
{ImageFilePath: tempdir + "/" + glyphImg[4]}, {ImageFilePath: tempdir + "/" + glyphImg[5]},
{ImageFilePath: tempdir + "/" + glyphImg[6]}, {ImageFilePath: tempdir + "/" + glyphImg[7]},
{ImageFilePath: tempdir + "/" + glyphImg[8]}, {ImageFilePath: tempdir + "/" + glyphImg[9]},
{ImageFilePath: tempdir + "/" + glyphImg[10]}, {ImageFilePath: tempdir + "/" + glyphImg[11]},
}
// create new image from grids
rgba, err := gim.New(grids, vert, horz).Merge()
if err != nil {
panic(err)
}
// save the output to png
file, err := os.Create(savename)
err = png.Encode(file, rgba)
if err != nil {
fmt.Println(err)
} }
} }
// load images for processing using github.com/ozankasikci/go-image-merge
grids := []*gim.Grid{
{ImageFilePath: glyphImg[0]}, {ImageFilePath: glyphImg[1]},
{ImageFilePath: glyphImg[2]}, {ImageFilePath: glyphImg[3]},
{ImageFilePath: glyphImg[4]}, {ImageFilePath: glyphImg[5]},
{ImageFilePath: glyphImg[6]}, {ImageFilePath: glyphImg[7]},
{ImageFilePath: glyphImg[8]}, {ImageFilePath: glyphImg[9]},
{ImageFilePath: glyphImg[10]}, {ImageFilePath: glyphImg[11]},
}
// create new image from grids
rgba, err := gim.New(grids, vert, horz).Merge()
if err != nil {
panic(err)
}
// save the output to png
file, err := os.Create(savename)
err = png.Encode(file, rgba)
if err != nil {
fmt.Println(err)
}
} }

2
go.mod
View File

@@ -1,4 +1,4 @@
module gitlab.com/Raum0x2A/nmslib module nmslib
go 1.16 go 1.16

32
lang.go
View File

@@ -3,6 +3,7 @@ package nmslib
import ( import (
"encoding/csv" "encoding/csv"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"strings" "strings"
) )
@@ -159,6 +160,7 @@ func toNMS(t Translate, csvlines [][]string) string {
return returnstring return returnstring
} }
/*
func openCSV(lagcsv string) [][]string { func openCSV(lagcsv string) [][]string {
csvFile, err := os.Open("./assets/lang/" + lagcsv) csvFile, err := os.Open("./assets/lang/" + lagcsv)
if err != nil { if err != nil {
@@ -172,4 +174,34 @@ func openCSV(lagcsv string) [][]string {
fmt.Println(err) fmt.Println(err)
} }
return csvlines return csvlines
*/
func openCSV(lagcsv string) [][]string {
// create temp dir
tempdir, err := ioutil.TempDir("", "nmslib-")
if err != nil {
panic(err)
}
defer os.RemoveAll(tempdir) // Clean up temp files
// extract language file from resources.go
data, err := Asset("assets/lang/" + lagcsv)
if err != nil {
panic(err)
}
// wirte extracted data to temp dir
err = ioutil.WriteFile(tempdir+"/"+lagcsv, []byte(data), 0644)
csvFile, err := os.Open(tempdir + "/" + lagcsv)
if err != nil {
fmt.Println(err)
}
defer csvFile.Close() // close language file when finished
// read csv file from memory
csvlines, err := csv.NewReader(csvFile).ReadAll()
if err != nil {
fmt.Println(err)
}
return csvlines
} }