2021-10-24 01:45:45 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/dhowden/tag"
|
|
|
|
"github.com/nfnt/resize"
|
2021-11-05 01:10:46 -06:00
|
|
|
"github.com/spf13/viper"
|
2021-10-24 01:45:45 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
Gets the Image Path from the uri to the string passed
|
|
|
|
if embedded image is found the path to that Image is returned else
|
|
|
|
path to default image is sent.
|
|
|
|
*/
|
|
|
|
func getAlbumArt(uri string) string {
|
2021-11-05 02:41:14 -06:00
|
|
|
var path string = viper.GetString("DEFAULT_IMAGE_PATH")
|
2021-10-24 01:45:45 -06:00
|
|
|
f, err := os.Open(uri)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
m, err := tag.ReadFrom(f)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
albumCover := m.Picture()
|
|
|
|
if albumCover != nil {
|
2021-11-05 02:41:14 -06:00
|
|
|
b, err := os.Create(viper.GetString("COVER_IMAGE_PATH"))
|
2021-10-24 01:45:45 -06:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer b.Close()
|
|
|
|
b.Write(albumCover.Data)
|
2021-11-05 02:41:14 -06:00
|
|
|
path = viper.GetString("COVER_IMAGE_PATH")
|
2021-10-24 01:45:45 -06:00
|
|
|
b.Close()
|
|
|
|
}
|
|
|
|
f.Close()
|
|
|
|
return path
|
|
|
|
}
|
|
|
|
|
|
|
|
func getImg(uri string) (image.Image, error) {
|
|
|
|
|
|
|
|
f, err := os.Open(uri)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer f.Close()
|
|
|
|
|
|
|
|
img, _, err := image.Decode(f)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-10-29 02:16:18 -06:00
|
|
|
fw, fh := getFontWidth()
|
|
|
|
img = resize.Resize(
|
2021-11-05 01:10:46 -06:00
|
|
|
uint(float32(IMG_W)*(fw+float32(viper.GetFloat64("IMAGE_WIDTH_EXTRA_X")))), uint(float32(IMG_H)*(fh+float32(viper.GetFloat64("IMAGE_WIDTH_EXTRA_Y")))),
|
2021-10-24 01:45:45 -06:00
|
|
|
img,
|
|
|
|
resize.Bilinear,
|
|
|
|
)
|
|
|
|
|
|
|
|
return img, nil
|
|
|
|
}
|