gomp/imageUtils.go
aditya-K2 9b1e8fd4f7 Image Preview Utilities
render.go : This File Contains the implementation for the Renderer which
is a channel that will receive strings to the path of decoded images)
the path is sent with the help of Send() method. The Start() method
starts the go routine OpenImage() this function blocks the image as it
keeps listening over the channel. which helps in not drawing the image
again and again.

imageUtils.go: This file contains the helper function for decoding
images.
2021-10-24 13:15:45 +05:30

62 lines
980 B
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("hello.jpg")
if err != nil {
panic(err)
}
defer b.Close()
b.Write(albumCover.Data)
path = "hello.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
}
img = resize.Thumbnail(
uint(IMG_W*22), uint(IMG_H*15),
img,
resize.Bilinear,
)
return img, nil
}