img

package
v0.0.0-...-cc6b2b6 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Meme

type Meme struct {
	// The gif.GIF for the image
	Gif *gif.GIF
	// TextBoxes to add
	TextBoxes *[]TextBox
	// Border (fraction of image size)
	Border float64
}

Meme is a structure describing a meme

func MemeFromFile

func MemeFromFile(path string, top string, bottom string, fontName string) (*Meme, error)

MemeFromFile initiates a simple meme from a gif

func (*Meme) Generate

func (m *Meme) Generate() error

Generate modifies the image adding the meme text

func (*Meme) GifMetaData

func (m *Meme) GifMetaData()

GifMetaData returns metadata on the gif

func (*Meme) NormalizeImage

func (m *Meme) NormalizeImage()

NormalizeImage modifies the image it so that it has all frames of the same size, with transparency.

func (*Meme) Preview

func (m *Meme) Preview(width, height uint) image.Image

Preview returns a square of the required width and height

type MemeTemplate

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

MemeTemplate represents all the basic information you need to generate a meme: the base image and the position, shape and font sizes in the text boxes.

func SimpleTemplate

func SimpleTemplate(imgPath string, fontName string, maxFontSize float64, minFontSize float64) (*MemeTemplate, error)

SimpleTemplate generates the simplest possible template: - one box in the top 1/3rd of the image - one box in the bottom 1/3rd of the image

func (*MemeTemplate) GetGif

func (tpl *MemeTemplate) GetGif() (*gif.GIF, error)

GetGif reads the gif from disk

func (*MemeTemplate) GetMeme

func (tpl *MemeTemplate) GetMeme(text ...string) (*Meme, error)

GetMeme fills a template with the text strings provided

type TextBox

type TextBox struct {
	// Text to write in the textbox
	Txt *string
	// Width of the textbox, in pixels
	Width int
	// Height of the textbox
	Height int
	// Position of the textbox in the image
	Center image.Point
	// Path to the font
	FontPath string
	// Line spacing (fraction of the fontsize)
	LineSpacingRatio float64
	// the actual font size.
	FontSize float64
}

TextBox represents a text box to add to the image.

func (*TextBox) CalculateFontSize

func (t *TextBox) CalculateFontSize(maxFontSize float64, minFontSize float64) (float64, error)

CalculateFontSize calculates the maximum font size that can fit the text in the textbox.

func (*TextBox) DrawText

func (t *TextBox) DrawText(ctx *gg.Context) error

DrawText draws the text into a gg context

func (*TextBox) SetText

func (t *TextBox) SetText(txt string, maxFontSize float64, minFontSize float64) error

SetText substitutes text into the textbox, and calculates the font size

Jump to

Keyboard shortcuts

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