2020-09-29 16:09:42 +00:00
|
|
|
package images
|
|
|
|
|
|
|
|
const (
|
2020-10-01 16:47:34 +00:00
|
|
|
UNKNOWN FileType = 1 + iota
|
|
|
|
|
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
|
|
|
|
)
|
|
|
|
|
2020-10-22 15:27:58 +00:00
|
|
|
const (
|
|
|
|
MaxJpegQuality = 80
|
|
|
|
MinJpegQuality = 50
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2020-10-22 15:59:01 +00:00
|
|
|
ResizeDimensions = []ResizeDimension{80, 240}
|
2020-10-22 15:27:58 +00:00
|
|
|
|
|
|
|
// DimensionSizeLimit the size limits imposed on each resize dimension
|
|
|
|
// Figures are based on the following sample data https://github.com/status-im/status-react/issues/11047#issuecomment-694970473
|
2020-10-22 15:59:01 +00:00
|
|
|
DimensionSizeLimit = map[ResizeDimension]DimensionLimits{
|
2020-10-22 15:27:58 +00:00
|
|
|
80: {
|
|
|
|
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)
|
|
|
|
},
|
|
|
|
240: {
|
|
|
|
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-22 15:59:01 +00:00
|
|
|
type DimensionLimits struct {
|
2020-10-22 15:27:58 +00:00
|
|
|
Ideal int
|
|
|
|
Max int
|
2020-09-29 16:09:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type FileType uint
|
2020-10-22 15:59:01 +00:00
|
|
|
type ResizeDimension uint
|