bae972f697
Image is now resized according to the font size and also a new globals.go files is added which contains all the globals. the Image width can also be changed according to use by adding or substracting pixels to it by changing the globals IMAGE_WIDTH_EXTRA_X, IMAGE_WIDTH_EXTRA_Y Also, now there is no need to specify where the music directory is the mpd.conf file in `~/.config/mpd/` is automatically parsed for music directory
63 lines
1.0 KiB
Go
63 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"image"
|
|
"os"
|
|
|
|
"github.com/dhowden/tag"
|
|
"github.com/nfnt/resize"
|
|
)
|
|
|
|
/*
|
|
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 {
|
|
var path string = "default.jpg"
|
|
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 {
|
|
b, err := os.Create("thumb.jpg")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
defer b.Close()
|
|
b.Write(albumCover.Data)
|
|
path = "thumb.jpg"
|
|
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
|
|
}
|
|
|
|
fw, fh := getFontWidth()
|
|
img = resize.Resize(
|
|
uint(float32(IMG_W)*(fw+IMAGE_WIDTH_EXTRA_X)), uint(float32(IMG_H)*(fh+IMAGE_WIDTH_EXTRA_Y)),
|
|
img,
|
|
resize.Bilinear,
|
|
)
|
|
|
|
return img, nil
|
|
}
|