background

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package background composes a backdrop — a solid color, gradient, or image — behind a piece of content, with optional padding, rounded corners, drop shadow, and blur.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Background

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

Background is a configurable backdrop. Build one with Solid, Gradient, Image, or ImageFromFile and chain the With* methods.

func Gradient

func Gradient(t GradientType, stops ...Stop) *Background

Gradient creates a gradient backdrop of the given type.

func Image

func Image(img image.Image) *Background

Image creates an image backdrop.

func ImageFromFile

func ImageFromFile(path string) (*Background, error)

ImageFromFile creates an image backdrop from a file on disk.

func Solid

func Solid(c color.Color) *Background

Solid creates a solid color backdrop.

func (*Background) Render

func (b *Background) Render(content image.Image) (image.Image, error)

Render draws the backdrop behind (and around) the content image. A nil content produces just the backdrop at its padding size.

func (*Background) WithAngle

func (b *Background) WithAngle(deg float64) *Background

WithAngle sets the gradient angle in degrees.

func (*Background) WithBlur

func (b *Background) WithBlur(style BlurStyle, radius float64) *Background

WithBlur blurs the backdrop (gradient and image backdrops only).

func (*Background) WithCenter

func (b *Background) WithCenter(x, y float64) *Background

WithCenter sets the gradient center as fractions of the canvas (0-1).

func (*Background) WithCornerRadius

func (b *Background) WithCornerRadius(r float64) *Background

WithCornerRadius rounds the corners of the backdrop.

func (*Background) WithIntensity

func (b *Background) WithIntensity(v float64) *Background

WithIntensity tunes spiral tightness and star point count.

func (*Background) WithOpacity

func (b *Background) WithOpacity(o float64) *Background

WithOpacity sets the opacity of an image backdrop (0-1).

func (*Background) WithPadding

func (b *Background) WithPadding(px int) *Background

WithPadding sets equal padding on all sides.

func (*Background) WithPaddingDetailed

func (b *Background) WithPaddingDetailed(top, right, bottom, left int) *Background

WithPaddingDetailed sets the padding of each side individually.

func (*Background) WithScaleMode

func (b *Background) WithScaleMode(m ScaleMode) *Background

WithScaleMode sets how an image backdrop is fitted.

func (*Background) WithShadow

func (b *Background) WithShadow(s *Shadow) *Background

WithShadow draws a drop shadow behind the content.

type BlurStyle

type BlurStyle int

BlurStyle selects the blur algorithm applied to a backdrop.

const (
	GaussianBlur BlurStyle = iota
	PixelatedBlur
)

type GradientType

type GradientType int

GradientType selects the shape of a gradient backdrop.

const (
	LinearGradient GradientType = iota
	RadialGradient
	AngularGradient
	DiamondGradient
	SpiralGradient
	SquareGradient
	StarGradient
)

type Padding

type Padding struct {
	Top, Right, Bottom, Left int
}

Padding is the space between the content and the canvas edge.

type ScaleMode

type ScaleMode int

ScaleMode controls how an image backdrop is fitted to the canvas.

const (
	Fit ScaleMode = iota
	Fill
	Cover
	Stretch
	Tile
)

type Shadow

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

Shadow describes a drop shadow drawn behind the content.

func NewShadow

func NewShadow() *Shadow

NewShadow creates a shadow with sensible defaults.

func (*Shadow) Apply

func (s *Shadow) Apply(content image.Image, cornerRadius float64) image.Image

Apply returns the content composited over its shadow, expanded to fit. cornerRadius should match the corner radius of the content so the shadow hugs its silhouette.

func (*Shadow) WithBlur

func (s *Shadow) WithBlur(radius float64) *Shadow

WithBlur sets the softness of the shadow edge.

func (*Shadow) WithColor

func (s *Shadow) WithColor(c color.Color) *Shadow

WithColor sets the shadow color.

func (*Shadow) WithOffset

func (s *Shadow) WithOffset(x, y float64) *Shadow

WithOffset moves the shadow relative to the content.

func (*Shadow) WithSpread

func (s *Shadow) WithSpread(radius float64) *Shadow

WithSpread grows the shadow beyond the content bounds.

type Stop

type Stop struct {
	Color    color.Color
	Position float64
}

Stop is a color at a position (0-1) along a gradient.

Jump to

Keyboard shortcuts

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