status-go/images/type.go

38 lines
705 B
Go
Raw Normal View History

package images
import (
"errors"
"github.com/status-im/status-go/protocol/protobuf"
)
2023-02-02 17:59:48 +00:00
func GetProtobufImageType(buf []byte) protobuf.ImageType {
switch GetType(buf) {
case JPEG:
2020-10-26 13:01:46 +00:00
return protobuf.ImageType_JPEG
2023-02-02 17:59:48 +00:00
case PNG:
2020-10-26 13:01:46 +00:00
return protobuf.ImageType_PNG
2023-02-02 17:59:48 +00:00
case GIF:
2020-10-26 13:01:46 +00:00
return protobuf.ImageType_GIF
2023-02-02 17:59:48 +00:00
case WEBP:
2020-10-26 13:01:46 +00:00
return protobuf.ImageType_WEBP
default:
2020-10-26 13:01:46 +00:00
return protobuf.ImageType_UNKNOWN_IMAGE_TYPE
}
}
2023-02-02 17:59:48 +00:00
func GetProtobufImageMime(buf []byte) (string, error) {
switch GetType(buf) {
case JPEG:
return "image/jpeg", nil
2023-02-02 17:59:48 +00:00
case PNG:
return "image/png", nil
2023-02-02 17:59:48 +00:00
case GIF:
return "image/gif", nil
2023-02-02 17:59:48 +00:00
case WEBP:
return "image/webp", nil
default:
return "", errors.New("mime type not found")
}
}