diff --git a/assets/glyphs/dark/PORTALSYMBOL.01.png b/assets/glyphs/dark/PORTALSYMBOL.1.png similarity index 100% rename from assets/glyphs/dark/PORTALSYMBOL.01.png rename to assets/glyphs/dark/PORTALSYMBOL.1.png diff --git a/assets/glyphs/dark/PORTALSYMBOL.02.png b/assets/glyphs/dark/PORTALSYMBOL.2.png similarity index 100% rename from assets/glyphs/dark/PORTALSYMBOL.02.png rename to assets/glyphs/dark/PORTALSYMBOL.2.png diff --git a/assets/glyphs/dark/PORTALSYMBOL.03.png b/assets/glyphs/dark/PORTALSYMBOL.3.png similarity index 100% rename from assets/glyphs/dark/PORTALSYMBOL.03.png rename to assets/glyphs/dark/PORTALSYMBOL.3.png diff --git a/assets/glyphs/dark/PORTALSYMBOL.04.png b/assets/glyphs/dark/PORTALSYMBOL.4.png similarity index 100% rename from assets/glyphs/dark/PORTALSYMBOL.04.png rename to assets/glyphs/dark/PORTALSYMBOL.4.png diff --git a/assets/glyphs/dark/PORTALSYMBOL.05.png b/assets/glyphs/dark/PORTALSYMBOL.5.png similarity index 100% rename from assets/glyphs/dark/PORTALSYMBOL.05.png rename to assets/glyphs/dark/PORTALSYMBOL.5.png diff --git a/assets/glyphs/dark/PORTALSYMBOL.06.png b/assets/glyphs/dark/PORTALSYMBOL.6.png similarity index 100% rename from assets/glyphs/dark/PORTALSYMBOL.06.png rename to assets/glyphs/dark/PORTALSYMBOL.6.png diff --git a/assets/glyphs/dark/PORTALSYMBOL.07.png b/assets/glyphs/dark/PORTALSYMBOL.7.png similarity index 100% rename from assets/glyphs/dark/PORTALSYMBOL.07.png rename to assets/glyphs/dark/PORTALSYMBOL.7.png diff --git a/assets/glyphs/dark/PORTALSYMBOL.08.png b/assets/glyphs/dark/PORTALSYMBOL.8.png similarity index 100% rename from assets/glyphs/dark/PORTALSYMBOL.08.png rename to assets/glyphs/dark/PORTALSYMBOL.8.png diff --git a/glyphbanner.go b/glyphbanner.go index bc01496..3a4df23 100644 --- a/glyphbanner.go +++ b/glyphbanner.go @@ -3,12 +3,9 @@ package nmslib import ( "fmt" "image/png" - "io/ioutil" "os" "strconv" - "github.com/nfnt/resize" - gim "github.com/ozankasikci/go-image-merge" ) @@ -18,24 +15,20 @@ var portalex string Portal Glyph hex string var savename string Output name of PNG file -var vopt int - 1 enables vertical banner - 0 enables horizontal banner +var opt int + 00 sets horizontal banner in light mode + 10 sets vertical banner in light mode + 01 sets horizontal banner in dark mode + 11 sets vertical banner in dark mode */ -func CreateBanner(portalhex string, savename string, vopt int) { +func CreateBanner(portalhex string, savename string, opt int) { var err error var GlyphHex [12]int64 var glyphImg [12]string + var mode string var vert 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 if len(portalhex) == 12 { // get hex value from each digit in given string to an array of int64 @@ -45,41 +38,36 @@ func CreateBanner(portalhex string, savename string, vopt int) { panic(err) } } + + // set options + if opt == 00 { // set vertical rendering in light mode + vert, horz = 12, 1 + mode = "light" + } else if opt == 01 { // set vertival in dark mode + vert, horz = 12, 1 + mode = "dark" + } else if opt == 11 { // set horizontal rendering in dark mode + vert, horz = 1, 12 + mode = "dark" + } else { // set horizontal rendering in light mode (classic/default) + vert, horz = 1, 12 + mode = "light" + } + // assign image location of its glyph hex value to an array of strings for j := 0; j < len(glyphImg); j++ { - glyphImg[j] = fmt.Sprintf("glyphs/GLYPH-%X.png", 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 + "/glyphs/") - if os.IsNotExist(err2) { - errDir := os.MkdirAll(tempdir+"/glyphs", 0755) - if errDir != nil { - panic(errDir) - } - } - - err = ioutil.WriteFile(tempdir+"/"+glyphImg[k], []byte(data), 0644) + glyphImg[j] = fmt.Sprintf("./assets/glyphs/%s/PORTALSYMBOL.%X.png", mode, GlyphHex[j]) } } + // 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]}, - } - - if vopt == 1 { // set vertical rendering - vert, horz = 1, 12 - } else { // set horizontal rendering (default) - vert, horz = 12, 1 + {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 @@ -88,13 +76,9 @@ func CreateBanner(portalhex string, savename string, vopt int) { panic(err) } - // Resize banner 768x64 - nuimg := resize.Resize(768, 64, rgba, resize.Lanczos3) - // save the output to png - fmt.Printf("Saving %s to %s\n", portalhex, savename) file, err := os.Create(savename) - err = png.Encode(file, nuimg) + err = png.Encode(file, rgba) if err != nil { fmt.Println(err) } diff --git a/nmslib_test.go b/nmslib_test.go index a256f6b..01ea5d6 100644 --- a/nmslib_test.go +++ b/nmslib_test.go @@ -10,6 +10,12 @@ func TestRndPortal(t *testing.T) { fmt.Println(RndPortal()) } +func TestCreateBanner(t *testing.T) { + fmt.Printf("\nTesting CreateBanner: ") + CreateBanner(RndPortal(), "/tmp/Test.png", 11) + fmt.Printf("Random Portal address rendered as `/tmp/Test.png`\n\n") +} + func TestPortal2Galactic(t *testing.T) { want, err := P2gc("006afa556c30") if err != nil { @@ -54,11 +60,6 @@ func TestGalactic2portal(t *testing.T) { } } -func TestCreateBanner(t *testing.T) { - fmt.Printf("\nTesting CreateBanner: ") - CreateBanner(RndPortal(), "/tmp/Test.png", 0) -} - func TestTranslate(t *testing.T) { want := Translate{"Paka"} if want.Atl2Eng() != "Awake" {