-
Notifications
You must be signed in to change notification settings - Fork 0
/
imageformat.go
44 lines (39 loc) · 1.28 KB
/
imageformat.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
package valueobject
import (
"fmt"
"github.com/gohugonet/hugoverse/internal/domain/resources"
"github.com/gohugonet/hugoverse/pkg/media"
)
// RequiresDefaultQuality returns if the default quality needs to be applied to
// images of this format.
func RequiresDefaultQuality(f resources.ImageFormat) bool {
return f == resources.JPEG || f == resources.WEBP
}
// SupportsTransparency reports whether it supports transparency in any form.
func SupportsTransparency(f resources.ImageFormat) bool {
return f != resources.JPEG
}
// DefaultExtension returns the default file extension of this format, starting with a dot.
// For example: .jpg for resources.JPEG
func DefaultExtension(f resources.ImageFormat) string {
return MediaType(f).FirstSuffix.FullSuffix
}
// MediaType returns the media type of this images, e.g. images/jpeg for resources.JPEG
func MediaType(f resources.ImageFormat) media.Type {
switch f {
case resources.JPEG:
return media.Builtin.JPEGType
case resources.PNG:
return media.Builtin.PNGType
case resources.GIF:
return media.Builtin.GIFType
case resources.TIFF:
return media.Builtin.TIFFType
case resources.BMP:
return media.Builtin.BMPType
case resources.WEBP:
return media.Builtin.WEBPType
default:
panic(fmt.Sprintf("%d is not a valid images format", f))
}
}