status-go/images/type.go

38 lines
721 B
Go
Raw Normal View History

package images
import (
"errors"
"github.com/status-im/status-go/protocol/protobuf"
)
func GetProtobufImageFormat(buf []byte) protobuf.ImageFormat {
2023-02-02 17:59:48 +00:00
switch GetType(buf) {
case JPEG:
return protobuf.ImageFormat_JPEG
2023-02-02 17:59:48 +00:00
case PNG:
return protobuf.ImageFormat_PNG
2023-02-02 17:59:48 +00:00
case GIF:
return protobuf.ImageFormat_GIF
2023-02-02 17:59:48 +00:00
case WEBP:
return protobuf.ImageFormat_WEBP
default:
return protobuf.ImageFormat_UNKNOWN_IMAGE_FORMAT
}
}
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")
}
}