LoadImage

This commit is contained in:
Michael Fogleman 2016-02-25 15:06:04 -05:00
parent 64d88fe46a
commit 9d56681560
3 changed files with 12 additions and 1 deletions

View File

@ -167,6 +167,7 @@ Sometimes you just don't want to write these yourself.
```go
Radians(degrees float64) float64
Degrees(radians float64) float64
LoadImage(path string) (image.Image, error)
LoadPNG(path string) (image.Image, error)
SavePNG(path string, im image.Image) error
```

View File

@ -13,7 +13,7 @@ func main() {
dc.Fill()
dc.Pop()
}
if im, err := gg.LoadPNG("examples/gopher.png"); err == nil {
if im, err := gg.LoadImage("examples/gopher.png"); err == nil {
dc.DrawImageAnchored(im, S/2, S/2, 0.5, 0.5)
}
dc.SavePNG("out.png")

10
util.go
View File

@ -24,6 +24,16 @@ func Degrees(radians float64) float64 {
return radians * 180 / math.Pi
}
func LoadImage(path string) (image.Image, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
im, _, err := image.Decode(file)
return im, err
}
func LoadPNG(path string) (image.Image, error) {
file, err := os.Open(path)
if err != nil {