1
0

webp_preset.go 730 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package config
  2. import "fmt"
  3. type WebpPresetKind int
  4. const (
  5. WebpPresetDefault WebpPresetKind = iota
  6. WebpPresetPhoto
  7. WebpPresetPicture
  8. WebpPresetDrawing
  9. WebpPresetIcon
  10. WebpPresetText
  11. )
  12. var WebpPresets = map[string]WebpPresetKind{
  13. "default": WebpPresetDefault,
  14. "photo": WebpPresetPhoto,
  15. "picture": WebpPresetPicture,
  16. "drawing": WebpPresetDrawing,
  17. "icon": WebpPresetIcon,
  18. "text": WebpPresetText,
  19. }
  20. func (wp WebpPresetKind) String() string {
  21. for k, v := range WebpPresets {
  22. if v == wp {
  23. return k
  24. }
  25. }
  26. return ""
  27. }
  28. func (wp WebpPresetKind) MarshalJSON() ([]byte, error) {
  29. for k, v := range WebpPresets {
  30. if v == wp {
  31. return []byte(fmt.Sprintf("%q", k)), nil
  32. }
  33. }
  34. return []byte("null"), nil
  35. }