service

package
v0.0.0-...-b42b4a3 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2025 License: AGPL-3.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultFont = "" // TODO
View Source
const (
	SolidProfileLuminance = 0.7
)
View Source
const (
	UserAgent = "WelcomerImageService (https://github.com/WelcomerTeam/Welcomer, " + VERSION + ")"
)
View Source
const VERSION = "0.0.1"

VERSION follows semantic versioning.

Variables

View Source
var (
	ErrMissingFrames     = fmt.Errorf("no frames to encode")
	ErrNoFontFound       = fmt.Errorf("no font found")
	ErrNotImplemented    = fmt.Errorf("not yet implemented")
	ErrAvatarFetchFailed = fmt.Errorf("failed to fetch avatar resource")
	ErrInvalidURL        = fmt.Errorf("url is invalid or untrusted")

	ErrInvalidHorizontalAlignment = fmt.Errorf("unknown horizontal alignment")
	ErrInvalidVerticalAlignment   = fmt.Errorf("unknown vertical alignment")
	ErrUnknownProfileBorderType   = fmt.Errorf("unknown profile border type")
	ErrUnknownProfileFloat        = fmt.Errorf("unknown profile float")
)

Functions

This section is empty.

Types

type Font

type Font struct {
	Font *sfnt.Font
}

type FontFace

type FontFace struct {
	Face *font.Face
}

type FullImage

type FullImage struct {
	// The image format that is represented
	Format welcomer.ImageFileType

	Frames []image.Image

	// Config is the global color table (palette), width and height. A nil or
	// empty-color.Palette Config.ColorModel means that each frame has its own
	// color table and there is no global color table.
	Config image.Config

	// The successive delay times, one per frame, in 100ths of a second.
	Delay []int

	// LoopCount controls the number of times an animation will be
	// restarted during display.
	LoopCount int

	// Disposal is the successive disposal methods, one per frame.
	Disposal []byte

	// BackgroundIndex is the background index in the global color table, for
	// use with the DisposalBackground disposal method.
	BackgroundIndex byte
}

FullImage stores the image and any extra information.

type GenerateImageArguments

type GenerateImageArguments struct {
	ImageOptions GenerateImageOptions

	// Avatar with mask and background pre-applied
	Avatar image.Image
}

type GenerateImageOptions

type GenerateImageOptions struct {
	ShowAvatar         bool
	GuildID            discord.Snowflake
	UserID             discord.Snowflake
	AllowAnimated      bool
	AvatarURL          string
	Theme              welcomer.ImageTheme
	Background         string
	Text               string
	TextFont           string
	TextStroke         int
	TextAlign          welcomer.ImageAlignment
	TextColor          color.RGBA
	TextStrokeColor    color.RGBA
	ImageBorderColor   color.RGBA
	ImageBorderWidth   int
	ProfileFloat       welcomer.ImageAlignment
	ProfileBorderColor color.RGBA
	ProfileBorderWidth int
	ProfileBorderCurve welcomer.ImageProfileBorderType
}

type GenerateThemeResponse

type GenerateThemeResponse struct {
	// Overlay
	Overlay image.Image

	// The target size of entire image
	TargetImageSize                     image.Rectangle
	TargetImageWidth, TargetImageHeight int

	// The target size of backgrounds. This is
	// equal to TargetImage however changes if
	// there is a border.
	TargetBackgroundSize                 image.Rectangle
	TargetBackgroundW, TargetBackgroundH int

	// Point to move from (0,0) when
	// rendering the backgrounds
	BackgroundAnchor image.Point

	// Point to move from (0,0) when
	// rendering the overlay
	OverlayAnchor image.Point
}

func CreateBadgeImage

func CreateBadgeImage(is *ImageService, args GenerateImageArguments) (resp *GenerateThemeResponse, err error)

func CreateRegularImage

func CreateRegularImage(
	is *ImageService, args GenerateImageArguments,
) (resp *GenerateThemeResponse, err error)

func CreateVerticalImage

func CreateVerticalImage(is *ImageService, args GenerateImageArguments) (resp *GenerateThemeResponse, err error)

type ImageService

type ImageService struct {
	StartTime time.Time

	Options ImageServiceOptions

	Client http.Client

	Fonts map[string]*Font
	// contains filtered or unexported fields
}

func NewImageService

func NewImageService(ctx context.Context, options ImageServiceOptions) (is *ImageService, err error)

NewImageService creates the service and initializes it.

func (*ImageService) Close

func (is *ImageService) Close() error

func (*ImageService) CreateFontPack

func (is *ImageService) CreateFontPack(font string, size float64) *MultiFace

CreateFontPack creates a pack of fonts with fallback and the one passed.

func (*ImageService) CreateFontPackHook

func (is *ImageService) CreateFontPackHook(f string) func(float64) font.Face

CreateFontPackHook returns a newFace function with an argument.

func (*ImageService) FetchAvatar

func (is *ImageService) FetchAvatar(ctx context.Context, avatarURL string) (image.Image, error)

func (*ImageService) FetchBackground

func (is *ImageService) FetchBackground(background string, allowAnimated bool, avatar image.Image, themeSize image.Rectangle) (FullImage, error)

func (*ImageService) FetchBackgroundDefault

func (is *ImageService) FetchBackgroundDefault(value string) (FullImage, error)

FetchBackgroundDefault returns an image from the static backgrounds.

func (*ImageService) FetchBackgroundSolid

func (is *ImageService) FetchBackgroundSolid(value string) (FullImage, error)

FetchBackgroundSolid returns an image using the color provided as the value.

func (*ImageService) FetchBackgroundSolidProfile

func (is *ImageService) FetchBackgroundSolidProfile(src image.Image) (FullImage, error)

FetchBackgroundSolidProfile uses the primary color of an avatar as the background. It attempts to identify the primary background color by analysing the provided image 'src'. It iterates through various thresholds for color luminance until a suitable color is found. It returns a FullImage structure representing the identified primary color as the background, or an error if the process encounters an issue.

func (*ImageService) FetchBackgroundStripes

func (is *ImageService) FetchBackgroundStripes(value string, themeSize image.Rectangle) (FullImage, error)

FetchBackgroundStripes generates a striped background image based on the provided value. The format expects to be started with "v:" for vertical stripes or "h:" for horizontal stripes. Then is followed by a comma-separated list of colors.

func (*ImageService) FetchBackgroundURL

func (is *ImageService) FetchBackgroundURL(value string, allowAnimated bool) (FullImage, error)

FetchBackgroundURL returns an image from a specific URL.

func (*ImageService) FetchBackgroundUnsplash

func (is *ImageService) FetchBackgroundUnsplash(value string) (FullImage, error)

FetchBackgroundUnsplash returns an image from unsplash, identified by the value.

func (*ImageService) FetchBackgroundWelcomer

func (is *ImageService) FetchBackgroundWelcomer(value string, allowAnimated bool) (FullImage, error)

FetchBackgroundWelcomer returns an image from the database.

func (*ImageService) FetchFont

func (is *ImageService) FetchFont(f string, size float64) (face *FontFace, font *Font, err error)

FetchFont fetches a font face with the specified size.

func (*ImageService) GenerateImage

func (is *ImageService) GenerateImage(ctx context.Context, imageOptions GenerateImageOptions) ([]byte, welcomer.ImageFileType, *welcomer.Timing, error)

func (*ImageService) Open

func (is *ImageService) Open()

type ImageServiceOptions

type ImageServiceOptions struct {
	Debug             bool
	Host              string
	PostgresAddress   string
	PrometheusAddress string
}

ImageServiceOptions represents any options passable when creating the image generation service

type MultiFace

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

func (*MultiFace) AddFace

func (f *MultiFace) AddFace(face font.Face)

AddFace adds a font.Face to the multiface.Face.

func (*MultiFace) AddTrueTypeFace

func (f *MultiFace) AddTrueTypeFace(face font.Face, fnt *sfnt.Font)

func (*MultiFace) Close

func (f *MultiFace) Close() error

func (*MultiFace) Glyph

func (f *MultiFace) Glyph(dot fixed.Point26_6, r rune) (dr image.Rectangle, mask image.Image, maskp image.Point, advance fixed.Int26_6, ok bool)

func (*MultiFace) GlyphAdvance

func (f *MultiFace) GlyphAdvance(r rune) (advance fixed.Int26_6, ok bool)

func (*MultiFace) GlyphBounds

func (f *MultiFace) GlyphBounds(r rune) (bounds fixed.Rectangle26_6, advance fixed.Int26_6, ok bool)

func (*MultiFace) Kern

func (f *MultiFace) Kern(r0, r1 rune) fixed.Int26_6

func (*MultiFace) Metrics

func (f *MultiFace) Metrics() font.Metrics

type MultiFaceEntry

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

type MultilineArguments

type MultilineArguments struct {
	DefaultFontSize float64 // default font size to start with

	X int
	Y int

	Width  int
	Height int

	Alignment welcomer.ImageAlignment

	StrokeWeight int
	StrokeColor  color.Color
	TextColor    color.Color

	Text string
}

MultilineArguments is a list of arguments for the DrawMultiline function.

Jump to

Keyboard shortcuts

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