-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.go
36 lines (31 loc) · 933 Bytes
/
helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package ish
import (
"image"
"io"
"os"
// Register all known image decoders from the standard library.
_ "image/gif"
_ "image/jpeg"
_ "image/png"
// Register all known image decoders from the extension library.
_ "golang.org/x/image/bmp"
_ "golang.org/x/image/tiff"
_ "golang.org/x/image/webp"
)
// LoadFile loads and decodes the named file, returning an image and the
// name of its format. If an error occurs, the returned image is nil and
// the value of format is undefined.
func LoadFile(filename string) (image.Image, string, error) {
rdr, err := os.Open(filename)
if err != nil {
return nil, "", err
}
defer rdr.Close()
return image.Decode(rdr)
}
// Decode reads from an io.Reader, returning an image and the name of its
// format. If an error occurs, the returned image is nil and the value of
// format is undefined.
func Decode(r io.Reader) (image.Image, string, error) {
return image.Decode(r)
}