Added dark mode option to CreateBanner() func

- Fixed PORTALSYMBOL file names
- Now using image files from assets/glyphs
- CreateBanner() func options tweaked
This commit is contained in:
Raum0x2A
2021-05-06 00:52:01 -06:00
parent 5077876106
commit ccbd68aee8
10 changed files with 38 additions and 53 deletions

View File

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 37 KiB

View File

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 38 KiB

View File

Before

Width:  |  Height:  |  Size: 42 KiB

After

Width:  |  Height:  |  Size: 42 KiB

View File

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View File

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 38 KiB

View File

Before

Width:  |  Height:  |  Size: 38 KiB

After

Width:  |  Height:  |  Size: 38 KiB

View File

@@ -3,12 +3,9 @@ package nmslib
import ( import (
"fmt" "fmt"
"image/png" "image/png"
"io/ioutil"
"os" "os"
"strconv" "strconv"
"github.com/nfnt/resize"
gim "github.com/ozankasikci/go-image-merge" gim "github.com/ozankasikci/go-image-merge"
) )
@@ -18,24 +15,20 @@ var portalex string
Portal Glyph hex string Portal Glyph hex string
var savename string var savename string
Output name of PNG file Output name of PNG file
var vopt int var opt int
1 enables vertical banner 00 sets horizontal banner in light mode
0 enables horizontal banner 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 err error
var GlyphHex [12]int64 var GlyphHex [12]int64
var glyphImg [12]string var glyphImg [12]string
var mode string
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
@@ -45,41 +38,36 @@ func CreateBanner(portalhex string, savename string, vopt int) {
panic(err) 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 // 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("glyphs/GLYPH-%X.png", 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 + "/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)
} }
} }
// load images for processing using github.com/ozankasikci/go-image-merge // load images for processing using github.com/ozankasikci/go-image-merge
grids := []*gim.Grid{ grids := []*gim.Grid{
{ImageFilePath: tempdir + "/" + glyphImg[0]}, {ImageFilePath: tempdir + "/" + glyphImg[1]}, {ImageFilePath: glyphImg[0]}, {ImageFilePath: glyphImg[1]},
{ImageFilePath: tempdir + "/" + glyphImg[2]}, {ImageFilePath: tempdir + "/" + glyphImg[3]}, {ImageFilePath: glyphImg[2]}, {ImageFilePath: glyphImg[3]},
{ImageFilePath: tempdir + "/" + glyphImg[4]}, {ImageFilePath: tempdir + "/" + glyphImg[5]}, {ImageFilePath: glyphImg[4]}, {ImageFilePath: glyphImg[5]},
{ImageFilePath: tempdir + "/" + glyphImg[6]}, {ImageFilePath: tempdir + "/" + glyphImg[7]}, {ImageFilePath: glyphImg[6]}, {ImageFilePath: glyphImg[7]},
{ImageFilePath: tempdir + "/" + glyphImg[8]}, {ImageFilePath: tempdir + "/" + glyphImg[9]}, {ImageFilePath: glyphImg[8]}, {ImageFilePath: glyphImg[9]},
{ImageFilePath: tempdir + "/" + glyphImg[10]}, {ImageFilePath: tempdir + "/" + glyphImg[11]}, {ImageFilePath: glyphImg[10]}, {ImageFilePath: glyphImg[11]},
}
if vopt == 1 { // set vertical rendering
vert, horz = 1, 12
} else { // set horizontal rendering (default)
vert, horz = 12, 1
} }
// create new image from grids // create new image from grids
@@ -88,13 +76,9 @@ func CreateBanner(portalhex string, savename string, vopt int) {
panic(err) panic(err)
} }
// Resize banner 768x64
nuimg := resize.Resize(768, 64, rgba, resize.Lanczos3)
// save the output to png // save the output to png
fmt.Printf("Saving %s to %s\n", portalhex, savename)
file, err := os.Create(savename) file, err := os.Create(savename)
err = png.Encode(file, nuimg) err = png.Encode(file, rgba)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }

View File

@@ -10,6 +10,12 @@ func TestRndPortal(t *testing.T) {
fmt.Println(RndPortal()) 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) { func TestPortal2Galactic(t *testing.T) {
want, err := P2gc("006afa556c30") want, err := P2gc("006afa556c30")
if err != nil { 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) { func TestTranslate(t *testing.T) {
want := Translate{"Paka"} want := Translate{"Paka"}
if want.Atl2Eng() != "Awake" { if want.Atl2Eng() != "Awake" {