Skip to content

Commit

Permalink
Added drawImage helper
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed Jul 19, 2019
1 parent 3e91889 commit e67f337
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package main
import (
"image"
"image/color"
"image/draw"
"io/ioutil"
"log"
"os"
"strconv"

"github.com/golang/freetype"
"github.com/golang/freetype/truetype"
"github.com/muesli/streamdeck"
"github.com/nfnt/resize"
"golang.org/x/image/font"
"golang.org/x/image/math/fixed"
)
Expand Down Expand Up @@ -61,6 +64,24 @@ func NewWidget(index uint8, id string, action *ActionConfig, config map[string]s
return nil
}

func drawImage(img *image.RGBA, path string, size uint, x uint, y uint) error {
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()

icon, _, err := image.Decode(f)
if err != nil {
return err
}

icon = resize.Resize(size, size, icon, resize.Lanczos3)
draw.Draw(img, image.Rect(int(x), int(y), int(x+size), int(y+size)), icon, image.Point{0, 0}, draw.Src)

return nil
}

func drawString(img *image.RGBA, ttf *truetype.Font, text string, fontsize float64, pt fixed.Point26_6) {
c := freetype.NewContext()
c.SetDPI(72)
Expand Down

0 comments on commit e67f337

Please sign in to comment.