2020-05-13 15:16:17 +02:00
|
|
|
package images
|
|
|
|
|
|
|
|
import (
|
2022-02-10 18:19:34 +01:00
|
|
|
"errors"
|
|
|
|
|
2020-05-13 15:16:17 +02:00
|
|
|
"github.com/status-im/status-go/protocol/protobuf"
|
|
|
|
)
|
|
|
|
|
2024-01-24 12:09:28 -08:00
|
|
|
func GetProtobufImageFormat(buf []byte) protobuf.ImageFormat {
|
2023-02-02 17:59:48 +00:00
|
|
|
switch GetType(buf) {
|
|
|
|
case JPEG:
|
2024-01-24 12:09:28 -08:00
|
|
|
return protobuf.ImageFormat_JPEG
|
2023-02-02 17:59:48 +00:00
|
|
|
case PNG:
|
2024-01-24 12:09:28 -08:00
|
|
|
return protobuf.ImageFormat_PNG
|
2023-02-02 17:59:48 +00:00
|
|
|
case GIF:
|
2024-01-24 12:09:28 -08:00
|
|
|
return protobuf.ImageFormat_GIF
|
2023-02-02 17:59:48 +00:00
|
|
|
case WEBP:
|
2024-01-24 12:09:28 -08:00
|
|
|
return protobuf.ImageFormat_WEBP
|
2020-05-14 07:40:40 +02:00
|
|
|
default:
|
2024-01-24 12:09:28 -08:00
|
|
|
return protobuf.ImageFormat_UNKNOWN_IMAGE_FORMAT
|
2020-05-13 15:16:17 +02:00
|
|
|
}
|
|
|
|
}
|
2022-02-10 18:19:34 +01:00
|
|
|
|
2023-02-02 17:59:48 +00:00
|
|
|
func GetProtobufImageMime(buf []byte) (string, error) {
|
|
|
|
switch GetType(buf) {
|
|
|
|
case JPEG:
|
2022-02-10 18:19:34 +01:00
|
|
|
return "image/jpeg", nil
|
2023-02-02 17:59:48 +00:00
|
|
|
case PNG:
|
2022-02-10 18:19:34 +01:00
|
|
|
return "image/png", nil
|
2023-02-02 17:59:48 +00:00
|
|
|
case GIF:
|
2022-02-10 18:19:34 +01:00
|
|
|
return "image/gif", nil
|
2023-02-02 17:59:48 +00:00
|
|
|
case WEBP:
|
2022-02-10 18:19:34 +01:00
|
|
|
return "image/webp", nil
|
|
|
|
default:
|
|
|
|
return "", errors.New("mime type not found")
|
|
|
|
}
|
|
|
|
}
|