background

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DarkColor is the default dark mode background color
	DarkColor = color.RGBA{R: 30, G: 30, B: 30, A: 255}
	// LightColor is the default light mode background color
	LightColor = color.RGBA{R: 240, G: 240, B: 240, A: 255}
)

Functions

This section is empty.

Types

type Background

type Background interface {
	// Render applies the background to the given content image
	// It returns a new image with the background applied
	Render(content image.Image) (image.Image, error)

	// WithCornerRadius sets the corner radius for the background
	WithCornerRadius(radius float64) Background

	// WithShadow sets the shadow configuration for the background
	WithShadow(shadow Shadow) Background
}

Background represents any type that can be used as a background

type ColorBackground

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

ColorBackground represents a solid color background

func NewColorBackground

func NewColorBackground() ColorBackground

NewColorBackground creates a new ColorBackground with the given color

func (ColorBackground) Render

func (bg ColorBackground) Render(content image.Image) (image.Image, error)

Render applies the background to the given content image It returns a new image with the background applied and the content centered

func (ColorBackground) WithColor added in v0.7.0

func (bg ColorBackground) WithColor(c color.Color) ColorBackground

WithColor sets the background color

func (ColorBackground) WithCornerRadius added in v0.7.0

func (bg ColorBackground) WithCornerRadius(radius float64) Background

WithCornerRadius sets the corner radius for the background

func (ColorBackground) WithPadding added in v0.7.0

func (bg ColorBackground) WithPadding(value int) ColorBackground

WithPadding sets equal padding for all sides

func (ColorBackground) WithPaddingDetailed added in v0.7.0

func (bg ColorBackground) WithPaddingDetailed(top, right, bottom, left int) ColorBackground

WithPaddingDetailed sets detailed padding for each side

func (ColorBackground) WithShadow added in v0.7.0

func (bg ColorBackground) WithShadow(shadow Shadow) Background

WithShadow sets the shadow configuration for the background

type GradientBackground

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

GradientBackground represents a gradient background

func NewGradientBackground

func NewGradientBackground(gradientType GradientType, stops ...GradientStop) GradientBackground

NewGradientBackground creates a new GradientBackground

func (GradientBackground) Render

func (bg GradientBackground) Render(content image.Image) (image.Image, error)

Render applies the gradient background to the given content image

func (GradientBackground) WithAngle added in v0.7.0

func (bg GradientBackground) WithAngle(angle float64) GradientBackground

WithAngle sets the angle for linear gradients (in degrees)

func (GradientBackground) WithCenter added in v0.7.0

func (bg GradientBackground) WithCenter(x, y float64) GradientBackground

WithCenter sets the center point for radial and angular gradients

func (GradientBackground) WithCornerRadius added in v0.7.0

func (bg GradientBackground) WithCornerRadius(radius float64) Background

WithCornerRadius sets the corner radius for the background

func (GradientBackground) WithIntensity added in v0.7.0

func (bg GradientBackground) WithIntensity(intensity float64) GradientBackground

WithIntensity sets the intensity modifier for special gradients

func (GradientBackground) WithPadding added in v0.7.0

func (bg GradientBackground) WithPadding(value int) GradientBackground

WithPadding sets equal padding for all sides

func (GradientBackground) WithPaddingDetailed added in v0.7.0

func (bg GradientBackground) WithPaddingDetailed(top, right, bottom, left int) GradientBackground

WithPaddingDetailed sets detailed padding for each side

func (GradientBackground) WithShadow added in v0.7.0

func (bg GradientBackground) WithShadow(shadow Shadow) Background

WithShadow sets the shadow configuration for the background

type GradientStop

type GradientStop struct {
	Color    color.Color
	Position float64 // Position between 0 and 1
}

GradientStop represents a color stop in a gradient

type GradientType

type GradientType int

GradientType represents the type of gradient

const (
	// LinearGradient represents a linear gradient
	LinearGradient GradientType = iota
	// RadialGradient represents a radial gradient
	RadialGradient
	// AngularGradient represents an angular/conic gradient
	AngularGradient
	// DiamondGradient represents a diamond-shaped gradient
	DiamondGradient
	// SpiralGradient represents a spiral-shaped gradient
	SpiralGradient
	// SquareGradient represents a square-shaped gradient
	SquareGradient
	// StarGradient represents a star-shaped gradient
	StarGradient
)

type ImageBackground

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

ImageBackground represents an image background

func NewImageBackground

func NewImageBackground(img image.Image) ImageBackground

NewImageBackground creates a new ImageBackground

func NewImageBackgroundFromFile added in v0.3.0

func NewImageBackgroundFromFile(path string) (ImageBackground, error)

NewImageBackgroundFromFile creates a new ImageBackground from a file path

func (ImageBackground) Render

func (bg ImageBackground) Render(content image.Image) (image.Image, error)

Render applies the image background to the given content image

func (ImageBackground) WithBlurRadius added in v0.7.0

func (bg ImageBackground) WithBlurRadius(radius float64) ImageBackground

WithBlurRadius sets the blur radius for the background image

func (ImageBackground) WithCornerRadius added in v0.7.0

func (bg ImageBackground) WithCornerRadius(radius float64) Background

WithCornerRadius sets the corner radius for the background

func (ImageBackground) WithOpacity added in v0.7.0

func (bg ImageBackground) WithOpacity(opacity float64) ImageBackground

WithOpacity sets the opacity of the background image (0.0 - 1.0)

func (ImageBackground) WithPadding added in v0.7.0

func (bg ImageBackground) WithPadding(value int) ImageBackground

WithPadding sets equal padding for all sides

func (ImageBackground) WithPaddingDetailed added in v0.7.0

func (bg ImageBackground) WithPaddingDetailed(top, right, bottom, left int) ImageBackground

WithPaddingDetailed sets detailed padding for each side

func (ImageBackground) WithScaleMode added in v0.7.0

func (bg ImageBackground) WithScaleMode(mode ImageScaleMode) ImageBackground

WithScaleMode sets the scaling mode for the image

func (ImageBackground) WithScaleModeString added in v0.7.0

func (bg ImageBackground) WithScaleModeString(mode string) ImageBackground

WithScaleModeString sets the scaling mode for the image from a string

func (ImageBackground) WithShadow added in v0.7.0

func (bg ImageBackground) WithShadow(shadow Shadow) Background

WithShadow sets the shadow configuration for the background

type ImageScaleMode

type ImageScaleMode int

ImageScaleMode determines how the image is scaled to fit the background

const (
	// ImageScaleFit scales the image to fit within the bounds while maintaining aspect ratio
	ImageScaleFit ImageScaleMode = iota
	// ImageScaleFill scales the image to fill the bounds while maintaining aspect ratio
	ImageScaleFill
	// ImageScaleCover scales the image to cover the entire area while maintaining aspect ratio (like CSS background-size: cover)
	ImageScaleCover
	// ImageScaleStretch stretches the image to exactly fit the bounds
	ImageScaleStretch
	// ImageScaleTile repeats the image to fill the bounds
	ImageScaleTile
)

type Padding

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

Padding represents padding values for a background

func NewPadding

func NewPadding(value int) Padding

NewPadding creates a new Padding with equal values on all sides

func NewPaddingHV

func NewPaddingHV(horizontal, vertical int) Padding

NewPaddingHV creates a new Padding with equal horizontal and vertical values

func (Padding) ToPoint

func (p Padding) ToPoint() image.Point

ToPoint converts the padding to an image.Point for compatibility This uses the horizontal (Left) and vertical (Top) values

type Shadow

type Shadow interface {
	// WithOffset sets the X and Y offset of the shadow
	WithOffset(x, y float64) Shadow

	// WithBlur sets the blur radius of the shadow
	WithBlur(radius float64) Shadow

	// WithSpread sets the spread radius of the shadow
	WithSpread(radius float64) Shadow

	// WithColor sets the color of the shadow
	WithColor(c color.Color) Shadow

	// WithCornerRadius sets the corner radius of the shadow
	WithCornerRadius(radius float64) Shadow

	// Apply applies the shadow effect to the given image
	Apply(img image.Image) image.Image
}

Shadow represents a shadow configuration that can be applied to a background

func NewShadow

func NewShadow() Shadow

NewShadow creates a new shadow with default values

Jump to

Keyboard shortcuts

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