Updates and Fixes #2

Merged
Raum0x2A merged 14 commits from develop into master 2021-05-07 10:03:09 -06:00
10 changed files with 38 additions and 53 deletions
Showing only changes of commit ccbd68aee8 - Show all commits

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 (
"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)
}

View File

@@ -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" {