nmslib: v0.1.0
This commit is contained in:
91
glyphbanner.go
Normal file
91
glyphbanner.go
Normal file
@@ -0,0 +1,91 @@
|
||||
package nmslib
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"image/png"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
gim "github.com/ozankasikci/go-image-merge"
|
||||
)
|
||||
|
||||
/*CreateBanner - Output PNG of Portal Glyphs
|
||||
Requires 3 vars and returns 0 var, Outputs a PNG file
|
||||
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
|
||||
*/
|
||||
func CreateBanner(portalhex string, savename string, vopt int) {
|
||||
var err error
|
||||
var GlyphHex [12]int64
|
||||
var glyphImg [12]string
|
||||
// verify len of portalhex
|
||||
if len(portalhex) == 12 {
|
||||
// get hex value from each digit in given string to an array of int64
|
||||
for i := 0; i < len(portalhex); i++ {
|
||||
GlyphHex[i], err = strconv.ParseInt(portalhex[i:int(i+1)], 16, 16)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
// 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("glyphs")
|
||||
if os.IsNotExist(err2) {
|
||||
errDir := os.MkdirAll("glyphs", 0755)
|
||||
if errDir != nil {
|
||||
panic(errDir)
|
||||
}
|
||||
}
|
||||
err = ioutil.WriteFile(glyphImg[k], []byte(data), 0644)
|
||||
}
|
||||
}
|
||||
// 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]},
|
||||
}
|
||||
if vopt == 1 {
|
||||
// Merge images horizontally
|
||||
rgba, err := gim.New(grids, 1, 12).Merge()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// save the output to png
|
||||
fmt.Printf("Saving %s to %s in vertical format\n", portalhex, savename)
|
||||
file, err := os.Create(savename)
|
||||
err = png.Encode(file, rgba)
|
||||
} else {
|
||||
// Merge images vertically
|
||||
rgba, err := gim.New(grids, 12, 1).Merge()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// save the output to png
|
||||
fmt.Printf("Saving %s to %s\n", portalhex, savename)
|
||||
file, err := os.Create(savename)
|
||||
err = png.Encode(file, rgba)
|
||||
}
|
||||
// remove glyphs folder to keep it clean
|
||||
errDir := os.RemoveAll("glyphs")
|
||||
if errDir != nil {
|
||||
panic(errDir)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user