wallart-server/cmd/wallartd/pixil.go

30 lines
599 B
Go
Raw Normal View History

2022-09-25 12:03:05 -06:00
package main
import (
"encoding/base64"
"strings"
)
// A naiive subset of what's in a .pixil file
type PixilFrame struct {
Active bool `json:"active"`
Preview string `json:"preview"`
}
type Pixil struct {
Width uint `json:"width"`
Height uint `json:"height"`
Frames []PixilFrame `json:"frames"`
}
func (frame *PixilFrame) GetPreview() []byte {
if !frame.Active {
return nil
}
if !strings.HasPrefix(frame.Preview, "data:image/png") {
return nil
}
png := strings.Split(frame.Preview, ",")[1]
preview, _ := base64.StdEncoding.DecodeString(png)
return preview
}