go_image_draw

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2023 License: MIT Imports: 16 Imported by: 0

README

go-image-draw

image draw multi font string text and emoji

Installation

go get -u github.com/web-xiaxia/go-image-draw

Examples

dc := NewTextDraw([]*truetype.Font{font1, font2}, &truetype.Options{
    Size: 80,
})
dc.DrawString(img, color.White, "draw multi font text and emoji 😊", 10, 85)

Reference code / Acknowledgement

  • fogleman/gg: Go Graphics is a library for rendering 2D graphics in pure Go.
  • emojis: Emojis.Wiki — Emoji Meanings Encyclopedia

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetEmojiImage added in v0.0.9

func GetEmojiImage(text string) (image.Image, bool)

func IsEmoji added in v0.0.9

func IsEmoji(text string) bool

func NewColorWitRGB

func NewColorWitRGB(r, g, b float64) color.Color

NewColorWitRGB sets the current color. r, g, b values should be between 0 and 1, inclusive. Alpha will be set to 1 (fully opaque).

func NewColorWitRGB255

func NewColorWitRGB255(r, g, b int) color.Color

NewColorWitRGB255 sets the current color. r, g, b values should be between 0 and 255, inclusive. Alpha will be set to 255 (fully opaque).

func NewColorWitRGBA

func NewColorWitRGBA(r, g, b, a float64) color.Color

NewColorWitRGBA sets the current color. r, g, b, a values should be between 0 and 1, inclusive.

func NewColorWitRGBA255

func NewColorWitRGBA255(r, g, b, a int) color.Color

NewColorWitRGBA255 sets the current color. r, g, b, a values should be between 0 and 255, inclusive.

func NewColorWithHex

func NewColorWithHex(x string) color.Color

NewColorWithHex sets the current color using a hex string. The leading pound sign (#) is optional. Both 3- and 6-digit variations are supported. 8 digits may be provided to set the alpha value as well.

func StrSplit added in v0.1.0

func StrSplit(reqStr string) []string

Types

type Align

type Align int
const (
	AlignLeft Align = iota
	AlignCenter
	AlignRight
)

type FaceInfo

type FaceInfo struct {
	Face font.Face
	Font *truetype.Font
}

type TextDraw

type TextDraw interface {
	// GetMetrics font.Metrics
	GetMetrics() font.Metrics
	// GetWidth returns the width of the text.
	GetWidth(text string) float64
	// GetHeight returns the height of the text.
	GetHeight() float64
	// GetTextWithWidth returns the text that fits in the specified width.
	GetTextWithWidth(text string, width float64) string
	// TextWrap x
	TextWrap(text string, width float64) []string
	// DrawString draws the specified text at the specified point.
	DrawString(im draw.Image, c color.Color, s string, x, y float64)
	// DrawStringAnchored draws the specified text at the specified anchor point.
	// The anchor point is x - w * ax, y - h * ay, where w, h is the size of the
	// text. Use ax=0.5, ay=0.5 to center the text at the specified point.
	DrawStringAnchored(im draw.Image, c color.Color, s string, x, y, ax, ay float64)
	// DrawStringWrapped word-wraps the specified string to the given max width
	// and then draws it at the specified anchor point using the given line
	// spacing and text alignment.
	DrawStringWrapped(im draw.Image, c color.Color, s string, x, y, ax, ay, width, lineSpacing float64, align Align) float64

	// DrawStringToDC draws the specified text at the specified point.
	DrawStringToDC(im *gg.Context, c color.Color, s string, x, y float64)
	// DrawStringAnchoredToDC draws the specified text at the specified anchor point.
	// The anchor point is x - w * ax, y - h * ay, where w, h is the size of the
	// text. Use ax=0.5, ay=0.5 to center the text at the specified point.
	DrawStringAnchoredToDC(im *gg.Context, c color.Color, s string, x, y, ax, ay float64)
	// DrawStringWrappedToDC word-wraps the specified string to the given max width
	// and then draws it at the specified anchor point using the given line
	// spacing and text alignment.
	DrawStringWrappedToDC(im *gg.Context, c color.Color, s string, x, y, ax, ay, width, lineSpacing float64, align Align) float64
}

func NewTextDraw

func NewTextDraw(fs []*truetype.Font, opts *truetype.Options) TextDraw

NewTextDraw creates a new TextDraw. fs is a list of truetype.Fonts, Search for and use text within the font in order of drawing.

Jump to

Keyboard shortcuts

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