forked from h2non/bimg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype.go
62 lines (54 loc) · 1.49 KB
/
type.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package bimg
// ImageType represents an image type value.
type ImageType int
const (
// UNKNOWN represents an unknow image type value.
UNKNOWN ImageType = iota
// JPEG represents the JPEG image type.
JPEG
// WEBP represents the WEBP image type.
WEBP
// PNG represents the PNG image type.
PNG
// TIFF represents the TIFF image type.
TIFF
// MAGICK represents the libmagick compatible genetic image type.
MAGICK
)
// ImageTypes stores as pairs of image types supported and its alias names.
var ImageTypes = map[ImageType]string{
JPEG: "jpeg",
PNG: "png",
WEBP: "webp",
TIFF: "tiff",
MAGICK: "magick",
}
// DetermineImageType determines the image type format (jpeg, png, webp or tiff)
func DetermineImageType(buf []byte) ImageType {
return vipsImageType(buf)
}
// DetermineImageTypeName determines the image type format by name (jpeg, png, webp or tiff)
func DetermineImageTypeName(buf []byte) string {
return ImageTypeName(vipsImageType(buf))
}
// IsTypeSupported checks if a given image type is supported
func IsTypeSupported(t ImageType) bool {
return ImageTypes[t] != ""
}
// IsTypeNameSupported checks if a given image type name is supported
func IsTypeNameSupported(t string) bool {
for _, name := range ImageTypes {
if name == t {
return true
}
}
return false
}
// ImageTypeName is used to get the human friendly name of an image format.
func ImageTypeName(t ImageType) string {
imageType := ImageTypes[t]
if imageType == "" {
return "unknown"
}
return imageType
}