Verified Commit 000bc27a authored by Jae's avatar Jae
Browse files

Cache blurhash files to avoid regeneration

parent 5e345d8b
Pipeline #34 passed with stage
in 32 seconds
......@@ -36,6 +36,23 @@ type Members struct {
Members []Website `json:"members"`
}
func appendCategory(a []string, b []string) []string {
var res []string
for _, f := range a {
inlist := false
for _, s := range b {
if f == s {
inlist = true
}
}
if !inlist {
res = append(res, f)
}
}
return res
}
func main() {
// Web service
r := gin.Default()
......@@ -57,25 +74,38 @@ func main() {
log.Fatal(err)
}
for _, file := range galphotos {
if file.Name() != ".gitkeep" {
imageF, _ := os.Open("./static/images/" + file.Name())
alreadyphotos, err := ioutil.ReadDir("./static/blurhash")
if err != nil {
log.Fatal(err)
}
loadedImage, err := jpeg.Decode(imageF)
if err != nil {
log.Fatal(err)
}
var photosbase []string
for _, photo := range galphotos {
photosbase = append(photosbase, photo.Name())
}
var photosblur []string
for _, photo := range alreadyphotos {
photosblur = append(photosblur, photo.Name())
}
str, _ := blurhash.Encode(4, 3, loadedImage)
fmt.Println(str)
testt := appendCategory(photosbase, photosblur)
img, err := blurhash.Decode(str, 300, 500, 1)
if err != nil {
log.Fatal(err)
}
f, _ := os.Create("./static/blurhash/" + file.Name())
_ = jpeg.Encode(f, img, nil)
for _, file := range testt {
imageF, _ := os.Open("./static/images/" + file)
loadedImage, err := jpeg.Decode(imageF)
if err != nil {
log.Fatal(err)
}
str, _ := blurhash.Encode(4, 3, loadedImage)
img, err := blurhash.Decode(str, 300, 500, 1)
if err != nil {
log.Fatal(err)
}
f, _ := os.Create("./static/blurhash/" + file)
_ = jpeg.Encode(f, img, nil)
}
store := persistence.NewInMemoryStore(time.Second)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment