-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
38 lines (34 loc) · 989 Bytes
/
config.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
37
38
// Package imagecoding provides go bindings for en-/de-coding images using
// image processing c libraries found in common systems
package imagecoding
import (
"bytes"
"image"
_ "image/gif"
_ "image/png"
"github.com/h2non/filetype"
_ "golang.org/x/image/bmp"
_ "golang.org/x/image/tiff"
)
// DecodeConfig is like image.DecodeConfig but supports additional formats
// For JPEGs it uses jpeg-turbos internal function for compatibility
func DecodeConfig(content []byte) (image.Config, string, error) {
if len(content) == 0 {
return image.Config{}, "", ErrEmptyInput
}
// Look at the magic bytes to determine the file type
kind, err := filetype.Match(content)
if err != nil {
return image.Config{}, "", image.ErrFormat
}
switch ImgFormat(kind.Extension) {
// If this is an image, resize it
case Jpeg:
return ConfigJpeg(content)
case Heif:
return ConfigHeif(content)
default:
c, fmt, err := image.DecodeConfig(bytes.NewReader(content))
return c, fmt, err
}
}