2020-05-13 13:16:17 +00:00
|
|
|
package images
|
|
|
|
|
|
|
|
import (
|
2022-02-10 17:19:34 +00:00
|
|
|
"errors"
|
|
|
|
|
2020-05-13 13:16:17 +00:00
|
|
|
"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
|
2020-05-14 05:40:40 +00:00
|
|
|
default:
|
2020-10-26 13:01:46 +00:00
|
|
|
return protobuf.ImageType_UNKNOWN_IMAGE_TYPE
|
2020-05-13 13:16:17 +00:00
|
|
|
}
|
|
|
|
}
|
2022-02-10 17:19:34 +00:00
|
|
|
|
2023-02-02 17:59:48 +00:00
|
|
|
func GetProtobufImageMime(buf []byte) (string, error) {
|
|
|
|
switch GetType(buf) {
|
|
|
|
case JPEG:
|
2022-02-10 17:19:34 +00:00
|
|
|
return "image/jpeg", nil
|
2023-02-02 17:59:48 +00:00
|
|
|
case PNG:
|
2022-02-10 17:19:34 +00:00
|
|
|
return "image/png", nil
|
2023-02-02 17:59:48 +00:00
|
|
|
case GIF:
|
2022-02-10 17:19:34 +00:00
|
|
|
return "image/gif", nil
|
2023-02-02 17:59:48 +00:00
|
|
|
case WEBP:
|
2022-02-10 17:19:34 +00:00
|
|
|
return "image/webp", nil
|
|
|
|
default:
|
|
|
|
return "", errors.New("mime type not found")
|
|
|
|
}
|
|
|
|
}
|