2018-11-14 17:08:36 +00:00
|
|
|
package freetype
|
|
|
|
|
|
|
|
import (
|
2018-11-16 09:58:44 +00:00
|
|
|
"image"
|
2018-11-15 16:57:41 +00:00
|
|
|
"os"
|
2018-11-16 09:58:44 +00:00
|
|
|
|
|
|
|
_ "image/png" // Add PNG file loading support
|
|
|
|
|
|
|
|
"golang.org/x/image/draw"
|
|
|
|
"golang.org/x/image/math/fixed"
|
2018-11-14 17:08:36 +00:00
|
|
|
)
|
|
|
|
|
2018-11-16 09:58:44 +00:00
|
|
|
const emojiScale = fixed.Int26_6(100)
|
|
|
|
|
|
|
|
func loadIconAtSize(path string, size fixed.Int26_6) (image.Image, error) {
|
|
|
|
file, err := os.Open(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
img, _, err := image.Decode(file)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
scale := size.Mul(emojiScale).Round()
|
|
|
|
scaled := image.NewRGBA(image.Rect(0, 0, scale, scale))
|
|
|
|
draw.BiLinear.Scale(scaled, scaled.Bounds(), img, img.Bounds(), draw.Over, nil)
|
|
|
|
|
|
|
|
return scaled, nil
|
|
|
|
}
|