imgtext

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2022 License: MIT Imports: 3 Imported by: 0

README

go-imgtext

Simple Go package for adding Text to an Image

Install

go get github.com/Brownymister/imgtext
testing
go test ./... -cover

Exmaple

Simple example of creating a new image with an specified text.

imageData := ImageData
    {
        BgImgPath: "/path/to/original/image",
        FontPath:  "/path/to/a/ttf/file",
        FontSize:  30,
        Text:      "Im a Cat!",
        X:         112.5,
        Y:         12,
        Color:     color.Black,
    }

// ceate new image
img := AddTextToImage(imageData)
// save created image with path
Save(img, "path/whete/new/image/has/to/be/saved")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ImageData

type ImageData struct {
	BgImgPath   string      // path to the image to add the text on
	BgImage     image.Image // image data load from file
	FontPath    string      // path to a .ttf file containgin the font of the text (always needed)
	FontSize    float64     // size of the text i.e. 20
	Text        string      //
	X           float64     // the X coordinate of the text
	Y           float64     // the Y coorginate of the text
	Color       color.Color // font color
	OutputImage image.Image // output image with the text
}

func (*ImageData) AddTextToImage added in v0.1.3

func (img *ImageData) AddTextToImage(Text string, X float64, Y float64, FontSize float64, FontPath string, Color color.Color) error

main function to add a text to an Image from an given ImageData structure

func (*ImageData) Save added in v0.1.3

func (img *ImageData) Save(path string) error

save the Image at the given path as png

type ImageFuncs added in v0.1.3

type ImageFuncs interface {
	AddTextToImage(Text string, X float64, Y float64, FontSize float64, FontPath string, Color color.Color) error

	Save(string) error
	// contains filtered or unexported methods
}

func NewImage added in v0.1.3

func NewImage(BgImagePath string) ImageFuncs

new image instance

Jump to

Keyboard shortcuts

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