imageengine

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidDimensions = errors.New("imageengine: invalid dimensions")
	ErrResourceLimit     = errors.New("imageengine: resource limit exceeded")
	ErrInvalidImage      = errors.New("imageengine: invalid image")
)

Functions

func AddNoise

func AddNoise(dst *image.RGBA, rng RandomSource, opts NoiseOptions) error

func CropCover

func CropCover(src image.Image, width, height int, limits Limits) (*image.RGBA, error)

func DrawSlot

func DrawSlot(dst *image.RGBA, at image.Point, mask *ShapeMask, fill, stroke color.Color, strokeWidth int) error

func ExtractPiece

func ExtractPiece(src image.Image, at image.Point, mask *ShapeMask) (*image.RGBA, error)

func PNGBytes

func PNGBytes(src image.Image, limits Limits) ([]byte, error)

func PNGDataURI

func PNGDataURI(src image.Image, limits Limits) (string, error)

func PlaceNonOverlapping

func PlaceNonOverlapping(rng RandomSource, bounds image.Rectangle, sizes []image.Point, padding, maxAttempts int) ([]image.Rectangle, error)

func RandomFloat64

func RandomFloat64(rng RandomSource) (float64, error)

func RandomInt

func RandomInt(rng RandomSource, min, max int) (int, error)

func RectsOverlapWithPadding

func RectsOverlapWithPadding(a, b image.Rectangle, padding int) bool

func RotateScale

func RotateScale(src image.Image, degrees, scale float64, limits Limits) (*image.RGBA, error)

Types

type Background

type Background interface {
	Render(engine *Engine, width, height int) (image.Image, error)
}

type Canvas

type Canvas struct {
	// contains filtered or unexported fields
}

func (*Canvas) DrawLayer

func (c *Canvas) DrawLayer(src image.Image, at image.Point, opacity uint8) error

func (*Canvas) Image

func (c *Canvas) Image() *image.RGBA

type CryptoRandom

type CryptoRandom struct{ Reader io.Reader }

func (CryptoRandom) Read

func (r CryptoRandom) Read(dst []byte) (int, error)

func (CryptoRandom) Uint64

func (r CryptoRandom) Uint64() (uint64, error)

type Engine

type Engine struct {
	Limits Limits
	Random RandomSource
}

func New

func New(limits Limits, rng RandomSource) *Engine

func (*Engine) NewCanvas

func (e *Engine) NewCanvas(width, height int, background color.Color) (*Canvas, error)

type GradientBackground

type GradientBackground struct{ From, To color.RGBA }

func (GradientBackground) Render

func (g GradientBackground) Render(engine *Engine, width, height int) (image.Image, error)

type Limits

type Limits struct {
	MaxWidth        int
	MaxHeight       int
	MaxPixels       int64
	MaxLayers       int
	MaxEncodedBytes int
}

func DefaultLimits

func DefaultLimits() Limits

type NoiseOptions

type NoiseOptions struct {
	Dots, Lines int
	MaxAlpha    uint8
}

type RandomSource

type RandomSource interface {
	Uint64() (uint64, error)
	Read([]byte) (int, error)
}

RandomSource permits deterministic tests while production uses crypto/rand.

type ShapeKind

type ShapeKind string
const (
	ShapePuzzle    ShapeKind = "puzzle"
	ShapeCircle    ShapeKind = "circle"
	ShapeTriangle  ShapeKind = "triangle"
	ShapeSquare    ShapeKind = "square"
	ShapeDiamond   ShapeKind = "diamond"
	ShapeTrapezoid ShapeKind = "trapezoid"
	ShapeShield    ShapeKind = "shield"
)

type ShapeMask

type ShapeMask struct {
	Kind    ShapeKind
	Alpha   *image.Alpha
	Padding int
}

func NewShapeMask

func NewShapeMask(kind ShapeKind, size, padding int, limits Limits) (*ShapeMask, error)

Jump to

Keyboard shortcuts

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