forked from h2non/imaginary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
type.go
51 lines (45 loc) · 878 Bytes
/
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
package main
import (
"strings"
"gopkg.in/h2non/bimg.v1"
)
func ExtractImageTypeFromMime(mime string) string {
mime = strings.Split(mime, ";")[0]
part := strings.Split(mime, "/")
if len(part) < 2 {
return ""
}
return strings.ToLower(part[1])
}
func IsImageMimeTypeSupported(mime string) bool {
format := ExtractImageTypeFromMime(mime)
return bimg.IsTypeNameSupported(format)
}
func ImageType(name string) bimg.ImageType {
ext := strings.ToLower(name)
if ext == "jpeg" {
return bimg.JPEG
}
if ext == "png" {
return bimg.PNG
}
if ext == "webp" {
return bimg.WEBP
}
if ext == "tiff" {
return bimg.TIFF
}
return bimg.UNKNOWN
}
func GetImageMimeType(code bimg.ImageType) string {
if code == bimg.PNG {
return "image/png"
}
if code == bimg.WEBP {
return "image/webp"
}
if code == bimg.TIFF {
return "image/tiff"
}
return "image/jpeg"
}