text2picture

package module
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2022 License: MIT Imports: 13 Imported by: 0

README

go-text2picture

package main

import (
	"fmt"
	"image/color"
	"io"
	"os"

	"github.com/zijiren233/go-text2picture"
)

func main() {
	pic := text2picture.NewPictureWithBackGround(text2picture.NewColorPicture(500, 100, text2picture.White), 320, 10, 5)
	pic.DrawWithBlack("test 123\n4321...")
	pic.DrawWithColor(text2picture.Red, "test color ... ")
	pic.PointOffset(0, float64(pic.NextLineDistance()))
	pic.DrawWithBlack("test offset")
	pic.DrawWithBlack("   test auto newline")
	f, err := os.OpenFile("./test.png", os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.ModePerm)
	if err != nil {
		fmt.Println(err)
		return
	}
	defer f.Close()
	io.Copy(f, pic.GeneratePicture())
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Transparent = image.Transparent
	White       = image.White
	Black       = image.Black
	Red         = image.NewUniform(color.RGBA{255, 0, 0, 255})
	Green       = image.NewUniform(color.RGBA{0, 255, 0, 255})
	Blue        = image.NewUniform(color.RGBA{0, 0, 255, 255})
)

Functions

func AutoNewPicture added in v1.1.0

func AutoNewPicture(width int, dpi float64, padding int, fontSize float64) *autoPicture

func LoadFont added in v1.1.1

func LoadFont(fontPath string) (*truetype.Font, error)

Load local fonts

func LoadPicture added in v1.1.0

func LoadPicture(filepath string) *image.RGBA

func NewColor added in v1.1.1

func NewColor(R, G, B, A uint8) *image.Uniform

func NewColorPicture added in v1.1.0

func NewColorPicture(width, height int, color color.Color) *image.RGBA

Color can be generated using text2picture.NewColor()

func NewPictureWithBackGround

func NewPictureWithBackGround(png *image.RGBA, dpi float64, padding int, fontSize float64) *picture

png: background padding: text left and right padding fontSize: font size in points

func RGBA added in v1.1.0

func RGBA(R, G, B, A uint8) *image.Uniform

func ReadFont

func ReadFont(fontfile io.Reader) (*truetype.Font, error)

func ReadPicture added in v1.1.0

func ReadPicture(file io.Reader) *image.RGBA

func SetDefaultFont

func SetDefaultFont(font *truetype.Font)

Types

This section is empty.

Jump to

Keyboard shortcuts

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