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"
|
|
|
|
)
|
|
|
|
|
2024-01-24 20:09:28 +00:00
|
|
|
func GetProtobufImageFormat(buf []byte) protobuf.ImageFormat {
|
2023-02-02 17:59:48 +00:00
|
|
|
switch GetType(buf) {
|
|
|
|
case JPEG:
|
2024-01-24 20:09:28 +00:00
|
|
|
return protobuf.ImageFormat_JPEG
|
2023-02-02 17:59:48 +00:00
|
|
|
case PNG:
|
2024-01-24 20:09:28 +00:00
|
|
|
return protobuf.ImageFormat_PNG
|
2023-02-02 17:59:48 +00:00
|
|
|
case GIF:
|
2024-01-24 20:09:28 +00:00
|
|
|
return protobuf.ImageFormat_GIF
|
2023-02-02 17:59:48 +00:00
|
|
|
case WEBP:
|
2024-01-24 20:09:28 +00:00
|
|
|
return protobuf.ImageFormat_WEBP
|
2020-05-14 05:40:40 +00:00
|
|
|
default:
|
2024-01-24 20:09:28 +00:00
|
|
|
return protobuf.ImageFormat_UNKNOWN_IMAGE_FORMAT
|
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")
|
|
|
|
}
|
|
|
|
}
|