Documentation
¶
Index ¶
- Constants
- Variables
- type Font
- type FontFace
- type FullImage
- type GenerateImageArguments
- type GenerateImageOptions
- type GenerateThemeResponse
- func CreateBadgeImage(is *ImageService, args GenerateImageArguments) (resp *GenerateThemeResponse, err error)
- func CreateRegularImage(is *ImageService, args GenerateImageArguments) (resp *GenerateThemeResponse, err error)
- func CreateVerticalImage(is *ImageService, args GenerateImageArguments) (resp *GenerateThemeResponse, err error)
- type ImageService
- func (is *ImageService) Close() error
- func (is *ImageService) CreateFontPack(font string, size float64) *MultiFace
- func (is *ImageService) CreateFontPackHook(f string) func(float64) font.Face
- func (is *ImageService) FetchAvatar(ctx context.Context, avatarURL string) (image.Image, error)
- func (is *ImageService) FetchBackground(background string, allowAnimated bool, avatar image.Image, ...) (FullImage, error)
- func (is *ImageService) FetchBackgroundDefault(value string) (FullImage, error)
- func (is *ImageService) FetchBackgroundSolid(value string) (FullImage, error)
- func (is *ImageService) FetchBackgroundSolidProfile(src image.Image) (FullImage, error)
- func (is *ImageService) FetchBackgroundStripes(value string, themeSize image.Rectangle) (FullImage, error)
- func (is *ImageService) FetchBackgroundURL(value string, allowAnimated bool) (FullImage, error)
- func (is *ImageService) FetchBackgroundUnsplash(value string) (FullImage, error)
- func (is *ImageService) FetchBackgroundWelcomer(value string, allowAnimated bool) (FullImage, error)
- func (is *ImageService) FetchFont(f string, size float64) (face *FontFace, font *Font, err error)
- func (is *ImageService) GenerateImage(ctx context.Context, imageOptions GenerateImageOptions) ([]byte, welcomer.ImageFileType, *welcomer.Timing, error)
- func (is *ImageService) Open()
- type ImageServiceOptions
- type MultiFace
- func (f *MultiFace) AddFace(face font.Face)
- func (f *MultiFace) AddTrueTypeFace(face font.Face, fnt *sfnt.Font)
- func (f *MultiFace) Close() error
- func (f *MultiFace) Glyph(dot fixed.Point26_6, r rune) (dr image.Rectangle, mask image.Image, maskp image.Point, advance fixed.Int26_6, ...)
- func (f *MultiFace) GlyphAdvance(r rune) (advance fixed.Int26_6, ok bool)
- func (f *MultiFace) GlyphBounds(r rune) (bounds fixed.Rectangle26_6, advance fixed.Int26_6, ok bool)
- func (f *MultiFace) Kern(r0, r1 rune) fixed.Int26_6
- func (f *MultiFace) Metrics() font.Metrics
- type MultiFaceEntry
- type MultilineArguments
Constants ¶
const DefaultFont = "" // TODO
const (
SolidProfileLuminance = 0.7
)
const (
UserAgent = "WelcomerImageService (https://github.com/WelcomerTeam/Welcomer, " + VERSION + ")"
)
const VERSION = "0.0.1"
VERSION follows semantic versioning.
Variables ¶
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 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 (*ImageService) FetchBackground ¶
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) 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) AddTrueTypeFace ¶
func (*MultiFace) GlyphAdvance ¶
func (*MultiFace) GlyphBounds ¶
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.