2020-09-29 16:09:42 +00:00
|
|
|
package images
|
|
|
|
|
|
|
|
const (
|
2020-10-26 15:16:41 +00:00
|
|
|
UNKNOWN ImageType = 1 + iota
|
2020-10-01 16:47:34 +00:00
|
|
|
|
2020-09-29 16:09:42 +00:00
|
|
|
// Raster image types
|
2020-10-01 16:47:34 +00:00
|
|
|
JPEG
|
2020-09-29 16:09:42 +00:00
|
|
|
PNG
|
|
|
|
GIF
|
|
|
|
WEBP
|
2024-03-12 20:47:51 +00:00
|
|
|
ICO
|
2020-09-29 16:09:42 +00:00
|
|
|
)
|
|
|
|
|
2020-10-22 15:27:58 +00:00
|
|
|
const (
|
|
|
|
MaxJpegQuality = 80
|
|
|
|
MinJpegQuality = 50
|
2020-10-27 15:14:00 +00:00
|
|
|
|
2020-11-05 17:35:20 +00:00
|
|
|
SmallDim = ResizeDimension(80)
|
|
|
|
LargeDim = ResizeDimension(240)
|
2020-10-27 15:14:00 +00:00
|
|
|
|
2022-04-15 18:20:12 +00:00
|
|
|
BannerDim = ResizeDimension(800)
|
|
|
|
|
2020-11-09 15:16:36 +00:00
|
|
|
SmallDimName = "thumbnail"
|
|
|
|
LargeDimName = "large"
|
2022-04-15 18:20:12 +00:00
|
|
|
|
|
|
|
BannerIdentityName = "banner"
|
2020-10-22 15:27:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-10-27 15:14:00 +00:00
|
|
|
// ResizeDimensions list of all available image resize sizes
|
2020-11-05 17:35:20 +00:00
|
|
|
ResizeDimensions = []ResizeDimension{SmallDim, LargeDim}
|
2020-10-22 15:27:58 +00:00
|
|
|
|
|
|
|
// DimensionSizeLimit the size limits imposed on each resize dimension
|
2022-07-17 13:37:14 +00:00
|
|
|
// Figures are based on the following sample data https://github.com/status-im/status-mobile/issues/11047#issuecomment-694970473
|
2022-09-02 13:59:52 +00:00
|
|
|
DimensionSizeLimit = map[ResizeDimension]FileSizeLimits{
|
2020-11-05 17:35:20 +00:00
|
|
|
SmallDim: {
|
2020-10-22 15:27:58 +00:00
|
|
|
Ideal: 2560, // Base on the largest sample image at quality 60% (2,554 bytes ∴ 1024 * 2.5)
|
|
|
|
Max: 5632, // Base on the largest sample image at quality 80% + 50% margin (3,683 bytes * 1.5 ≈ 5500 ∴ 1024 * 5.5)
|
|
|
|
},
|
2020-11-05 17:35:20 +00:00
|
|
|
LargeDim: {
|
2020-10-22 15:27:58 +00:00
|
|
|
Ideal: 16384, // Base on the largest sample image at quality 60% (16,143 bytes ∴ 1024 * 16)
|
|
|
|
Max: 38400, // Base on the largest sample image at quality 80% + 50% margin (24,290 bytes * 1.5 ≈ 37500 ∴ 1024 * 37.5)
|
|
|
|
},
|
|
|
|
}
|
2020-10-27 15:14:00 +00:00
|
|
|
|
|
|
|
// ResizeDimensionToName maps a ResizeDimension to its assigned string name
|
|
|
|
ResizeDimensionToName = map[ResizeDimension]string{
|
2020-11-09 15:16:36 +00:00
|
|
|
SmallDim: SmallDimName,
|
|
|
|
LargeDim: LargeDimName,
|
2020-10-27 15:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NameToResizeDimension maps a string name to its assigned ResizeDimension
|
|
|
|
NameToResizeDimension = map[string]ResizeDimension{
|
2020-11-09 15:16:36 +00:00
|
|
|
SmallDimName: SmallDim,
|
|
|
|
LargeDimName: LargeDim,
|
2020-10-27 15:14:00 +00:00
|
|
|
}
|
2020-10-22 15:27:58 +00:00
|
|
|
)
|
|
|
|
|
2022-09-02 13:59:52 +00:00
|
|
|
type FileSizeLimits struct {
|
2020-10-22 15:27:58 +00:00
|
|
|
Ideal int
|
|
|
|
Max int
|
2020-09-29 16:09:42 +00:00
|
|
|
}
|
|
|
|
|
2020-10-26 15:16:41 +00:00
|
|
|
type ImageType uint
|
2020-10-22 15:59:01 +00:00
|
|
|
type ResizeDimension uint
|
2022-04-15 18:20:12 +00:00
|
|
|
|
2022-09-02 13:59:52 +00:00
|
|
|
func GetBannerDimensionLimits() FileSizeLimits {
|
|
|
|
return FileSizeLimits{
|
2022-04-15 18:20:12 +00:00
|
|
|
Ideal: 307200, // We want to save space and traffic but keep to maximum compression
|
|
|
|
Max: 460800, // Can't go bigger than 450 KB
|
|
|
|
}
|
|
|
|
}
|