Documentation ¶
Index ¶
- Constants
- Variables
- func CompressToFileLimits(bb *bytes.Buffer, img image.Image, bounds FileSizeLimits) error
- func Crop(img image.Image, rect image.Rectangle) (image.Image, error)
- func CropCenter(img image.Image) (image.Image, error)
- func Decode(fileName string) (image.Image, error)
- func DecodeFromURL(path string) (image.Image, error)
- func Encode(w io.Writer, img image.Image, config EncodeConfig) error
- func EncodeToBestSize(bb *bytes.Buffer, img image.Image, size ResizeDimension) error
- func EncodeToLimits(bb *bytes.Buffer, img image.Image, bounds FileSizeLimits) error
- func GetMimeType(buf []byte) (string, error)
- func GetPayloadDataURI(payload []byte) (string, error)
- func GetPayloadFromURI(uri string) ([]byte, error)
- func Resize(size ResizeDimension, img image.Image) image.Image
- func ResizeTo(percent int, img image.Image) image.Image
- func ShrinkOnly(size ResizeDimension, img image.Image) image.Image
- type CroppedImage
- type EncodeConfig
- type FileSizeError
- type FileSizeLimits
- type IdentityImage
- func GenerateBannerImage(filepath string, aX, aY, bX, bY int) (*IdentityImage, error)
- func GenerateIdentityImages(filepath string, aX, aY, bX, bY int) ([]IdentityImage, error)
- func GenerateIdentityImagesFromURL(url string) ([]IdentityImage, error)
- func GenerateImageVariants(cImg image.Image) ([]IdentityImage, error)
- func SampleIdentityImages() []IdentityImage
- func (i *IdentityImage) FromProtobuf(ii *protobuf.MultiAccount_IdentityImage)
- func (i IdentityImage) GetDataURI() (string, error)
- func (i IdentityImage) GetType() (ImageType, error)
- func (i IdentityImage) Hash() []byte
- func (i IdentityImage) IsEmpty() bool
- func (i IdentityImage) MarshalJSON() ([]byte, error)
- func (i *IdentityImage) ToProtobuf() *protobuf.MultiAccount_IdentityImage
- type ImageType
- type ResizeDimension
Constants ¶
const ( MaxJpegQuality = 80 MinJpegQuality = 50 SmallDim = ResizeDimension(80) LargeDim = ResizeDimension(240) BannerDim = ResizeDimension(800) SmallDimName = "thumbnail" LargeDimName = "large" BannerIdentityName = "banner" )
Variables ¶
var ( // ResizeDimensions list of all available image resize sizes ResizeDimensions = []ResizeDimension{SmallDim, LargeDim} // DimensionSizeLimit the size limits imposed on each resize dimension // Figures are based on the following sample data https://github.com/status-im/status-mobile/issues/11047#issuecomment-694970473 DimensionSizeLimit = map[ResizeDimension]FileSizeLimits{ SmallDim: { Ideal: 2560, Max: 5632, }, LargeDim: { Ideal: 16384, Max: 38400, }, } // ResizeDimensionToName maps a ResizeDimension to its assigned string name ResizeDimensionToName = map[ResizeDimension]string{ SmallDim: SmallDimName, LargeDim: LargeDimName, } // NameToResizeDimension maps a string name to its assigned ResizeDimension NameToResizeDimension = map[string]ResizeDimension{ SmallDimName: SmallDim, LargeDimName: LargeDim, } )
Functions ¶
func CompressToFileLimits ¶ added in v0.108.2
CompressToFileLimits takes an image.Image and analyses the pixel dimensions, if the longest side is greater than the `longSideMax` image.Image will be resized, before compression begins. Next the image.Image is repeatedly encoded and resized until the data fits within the given FileSizeLimits. There is no limit on the number of times the cycle is performed, the image.Image is reduced to 95% of its size at the end of every round the file size exceeds the given limits.
func CropCenter ¶ added in v0.87.2
CropCenter takes an image, usually downloaded from a URL If the image is square, the full image is returned If the image is rectangular, the largest central square is returned calculations at _docs/image-center-crop-calculations.png
func EncodeToBestSize ¶
func EncodeToLimits ¶ added in v0.100.0
func GetMimeType ¶
func GetPayloadDataURI ¶
func GetPayloadFromURI ¶ added in v0.108.2
func ShrinkOnly ¶ added in v0.100.0
func ShrinkOnly(size ResizeDimension, img image.Image) image.Image
Types ¶
type CroppedImage ¶ added in v0.100.0
type EncodeConfig ¶
type EncodeConfig struct {
Quality int
}
type FileSizeError ¶ added in v0.108.2
type FileSizeError struct {
// contains filtered or unexported fields
}
func (*FileSizeError) Error ¶ added in v0.108.2
func (e *FileSizeError) Error() string
type FileSizeLimits ¶ added in v0.108.2
func GetBannerDimensionLimits ¶ added in v0.100.0
func GetBannerDimensionLimits() FileSizeLimits
type IdentityImage ¶
type IdentityImage struct { KeyUID string `json:"keyUID"` Name string `json:"name"` Payload []byte `json:"payload"` Width int `json:"width"` Height int `json:"height"` FileSize int `json:"fileSize"` ResizeTarget int `json:"resizeTarget"` Clock uint64 `json:"clock"` }
func GenerateBannerImage ¶ added in v0.100.0
func GenerateBannerImage(filepath string, aX, aY, bX, bY int) (*IdentityImage, error)
func GenerateIdentityImages ¶
func GenerateIdentityImages(filepath string, aX, aY, bX, bY int) ([]IdentityImage, error)
func GenerateIdentityImagesFromURL ¶ added in v0.87.2
func GenerateIdentityImagesFromURL(url string) ([]IdentityImage, error)
func GenerateImageVariants ¶ added in v0.87.2
func GenerateImageVariants(cImg image.Image) ([]IdentityImage, error)
func SampleIdentityImages ¶
func SampleIdentityImages() []IdentityImage
func (*IdentityImage) FromProtobuf ¶ added in v0.106.1
func (i *IdentityImage) FromProtobuf(ii *protobuf.MultiAccount_IdentityImage)
func (IdentityImage) GetDataURI ¶
func (i IdentityImage) GetDataURI() (string, error)
func (IdentityImage) GetType ¶
func (i IdentityImage) GetType() (ImageType, error)
func (IdentityImage) Hash ¶
func (i IdentityImage) Hash() []byte
func (IdentityImage) IsEmpty ¶ added in v0.106.1
func (i IdentityImage) IsEmpty() bool
func (IdentityImage) MarshalJSON ¶
func (i IdentityImage) MarshalJSON() ([]byte, error)
func (*IdentityImage) ToProtobuf ¶ added in v0.106.1
func (i *IdentityImage) ToProtobuf() *protobuf.MultiAccount_IdentityImage
type ResizeDimension ¶
type ResizeDimension uint