images

package
v0.94.10 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2022 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxJpegQuality = 80
	MinJpegQuality = 50

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

	SmallDimName = "thumbnail"
	LargeDimName = "large"
)

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-react/issues/11047#issuecomment-694970473
	DimensionSizeLimit = map[ResizeDimension]DimensionLimits{
		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 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)

CropImage takes an image, usually downloaded from a URL If the image is square, the full image is returned It 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 Encode

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

func EncodeToBestSize

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

func GetMimeType

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

func GetPayloadDataURI

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

func Resize

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

Types

type DimensionLimits

type DimensionLimits struct {
	Ideal int
	Max   int
}

type EncodeConfig

type EncodeConfig struct {
	Quality int
}

type IdentityImage

type IdentityImage struct {
	KeyUID       string
	Name         string
	Payload      []byte
	Width        int
	Height       int
	FileSize     int
	ResizeTarget int
}

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) 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) MarshalJSON

func (i IdentityImage) MarshalJSON() ([]byte, error)

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 ResizeDimension

type ResizeDimension uint

Jump to

Keyboard shortcuts

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