images

package
v0.167.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2023 License: MPL-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxJpegQuality = 80
	MinJpegQuality = 50

	SmallDim = ResizeDimension(80)
	LargeDim = ResizeDimension(240)

	BannerDim = ResizeDimension(800)

	SmallDimName = "thumbnail"
	LargeDimName = "large"

	BannerIdentityName = "banner"
)
View Source
const AssetDebug = false

AssetDebug is true if the assets were built with the debug flag enabled.

Variables

View Source
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,
	}
)
View Source
var DefaultBounds = FileSizeLimits{Ideal: idealTargetImageSize, Max: resizeTargetImageSize}

Functions

func AddPadding added in v0.135.0

func AddPadding(img image.Image, padding int) *image.RGBA

func AddStatusIndicatorToImage added in v0.163.9

func AddStatusIndicatorToImage(inputImage []byte, innerColor color.Color, indicatorSize, indicatorBorder, indicatorCenterToEdge float64) ([]byte, error)

func Asset added in v0.135.0

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDigest added in v0.135.0

func AssetDigest(name string) ([sha256.Size]byte, error)

AssetDigest returns the digest of the file with the given name. It returns an error if the asset could not be found or the digest could not be loaded.

func AssetDir added in v0.135.0

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"}, AssetDir("data/img") would return []string{"a.png", "b.png"}, AssetDir("foo.txt") and AssetDir("notexist") would return an error, and AssetDir("") will return []string{"data"}.

func AssetInfo added in v0.135.0

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames added in v0.135.0

func AssetNames() []string

AssetNames returns the names of the assets.

func AssetString added in v0.135.0

func AssetString(name string) (string, error)

AssetString returns the asset contents as a string (instead of a []byte).

func CompressToFileLimits added in v0.108.2

func CompressToFileLimits(bb *bytes.Buffer, img image.Image, bounds FileSizeLimits) error

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 CreateCircleWithPadding added in v0.154.1

func CreateCircleWithPadding(img image.Image, padding int) *image.RGBA

func Crop

func Crop(img image.Image, rect image.Rectangle) (image.Image, error)

func CropCenter added in v0.87.2

func CropCenter(img image.Image) (image.Image, error)

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 Decode

func Decode(fileName string) (image.Image, error)

func DecodeFromURL added in v0.87.2

func DecodeFromURL(path string) (image.Image, error)

func DecodeImageData added in v0.163.14

func DecodeImageData(buf []byte, r io.Reader) (img image.Image, err error)

func Digests added in v0.135.0

func Digests() (map[string][sha256.Size]byte, error)

Digests returns a map of all known files and their checksums.

func Encode

func Encode(w io.Writer, img image.Image, config EncodeConfig) error

func EncodePNG added in v0.135.0

func EncodePNG(img *image.RGBA) ([]byte, error)

func EncodeToBestSize

func EncodeToBestSize(bb *bytes.Buffer, img image.Image, size ResizeDimension) error

func EncodeToLimits added in v0.100.0

func EncodeToLimits(bb *bytes.Buffer, img image.Image, bounds FileSizeLimits) error

func ExtractInitials added in v0.163.9

func ExtractInitials(fullName string, amountInitials int) string

func GenerateInitialsImage added in v0.163.9

func GenerateInitialsImage(initials string, bgColor, fontColor color.Color, fontFile string, size int, fontSize float64, uppercaseRatio float64) ([]byte, error)

GenerateInitialsImage uppercaseRatio is <height of any upper case> / dc.FontHeight() (line height) 0.60386123 for Inter-UI-Medium.otf

func GetImageDimensions added in v0.135.0

func GetImageDimensions(imgBytes []byte) (int, int, error)

func GetMimeType

func GetMimeType(buf []byte) (string, error)

func GetPayloadDataURI

func GetPayloadDataURI(payload []byte) (string, error)

func GetPayloadFromURI added in v0.108.2

func GetPayloadFromURI(uri string) ([]byte, error)

func GetProtobufImageMime added in v0.129.3

func GetProtobufImageMime(buf []byte) (string, error)

func GetProtobufImageType added in v0.129.3

func GetProtobufImageType(buf []byte) protobuf.ImageType

func ImageToBytes added in v0.135.0

func ImageToBytes(imagePath string) ([]byte, error)

func ImageToBytesAndImage added in v0.163.9

func ImageToBytesAndImage(imagePath string) ([]byte, image.Image, error)

func IsGif added in v0.163.14

func IsGif(buf []byte) bool

func IsJpeg added in v0.163.14

func IsJpeg(buf []byte) bool

func IsPayloadDataURI added in v0.163.14

func IsPayloadDataURI(uri string) bool

func IsPng added in v0.163.14

func IsPng(buf []byte) bool

func IsWebp added in v0.163.14

func IsWebp(buf []byte) bool

func MustAsset added in v0.135.0

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func MustAssetString added in v0.135.0

func MustAssetString(name string) string

MustAssetString is like AssetString but panics when Asset would return an error. It simplifies safe initialization of global variables.

func OpenAndAdjustImage added in v0.129.3

func OpenAndAdjustImage(inputImage CroppedImage, crop bool) ([]byte, error)

func ParseColor added in v0.163.9

func ParseColor(colorStr string) (color.RGBA, error)

func PlaceCircleInCenter added in v0.135.0

func PlaceCircleInCenter(paddedImg, circle *image.RGBA) *image.RGBA

func Resize

func Resize(size ResizeDimension, img image.Image) image.Image

func ResizeImage added in v0.135.0

func ResizeImage(imgBytes []byte, width, height int) ([]byte, error)

func ResizeTo added in v0.108.2

func ResizeTo(percent int, img image.Image) image.Image

func RestoreAsset added in v0.135.0

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory.

func RestoreAssets added in v0.135.0

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively.

func RoundCrop added in v0.163.9

func RoundCrop(inputImage []byte) ([]byte, error)

func ShrinkOnly added in v0.100.0

func ShrinkOnly(size ResizeDimension, img image.Image) image.Image

func SuperimposeLogoOnQRImage added in v0.135.0

func SuperimposeLogoOnQRImage(imageBytes []byte, qrFilepath []byte) []byte

Types

type Circle added in v0.135.0

type Circle struct {
	X, Y, R int
}

func (*Circle) At added in v0.135.0

func (c *Circle) At(x, y int) color.Color

func (*Circle) Bounds added in v0.135.0

func (c *Circle) Bounds() image.Rectangle

func (*Circle) ColorModel added in v0.135.0

func (c *Circle) ColorModel() color.Model

type CroppedImage added in v0.100.0

type CroppedImage struct {
	ImagePath string `json:"imagePath"`
	X         int    `json:"x"`
	Y         int    `json:"y"`
	Width     int    `json:"width"`
	Height    int    `json:"height"`
}

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

type FileSizeLimits struct {
	Ideal int
	Max   int
}

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"`
	LocalURL     string `json:"localUrl,omitempty"`
}

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 SampleIdentityImageForQRCode added in v0.135.0

func SampleIdentityImageForQRCode() []IdentityImage

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

type ImageType

type ImageType uint
const (
	UNKNOWN ImageType = 1 + iota

	// Raster image types
	JPEG
	PNG
	GIF
	WEBP
)

func GetType

func GetType(buf []byte) ImageType

type RGBA added in v0.163.9

type RGBA struct {
	R, G, B, A float64
}

type ResizeDimension

type ResizeDimension uint

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL