iteng

package
v0.0.0-...-c654c46 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyOpacity

func ApplyOpacity(img image.Image, opacity float64) image.Image

ApplyOpacity multiplies alpha channel by opacity

func ImageDriver

func ImageDriver(templatePath string, inputsPath string, outputPath string) error

func LoadImageFromFile

func LoadImageFromFile(path string) (image.Image, error)

LoadImageFromFile decodes common image formats

func MakeMask

func MakeMask(maskType string, w, h int, radius float64) *image.Alpha

MakeMask returns an *image.Alpha mask for the requested shape

func ResizeImage

func ResizeImage(src image.Image, dstW, dstH int, mode ResizeMode) image.Image

ResizeImage implements fill/fit/cover.

func SaveImageToFile

func SaveImageToFile(img image.Image, outpath, format string) error

SaveImageToFile encodes and saves image to file with specified format

Types

type Inputs

type Inputs map[string]string

Inputs map slotID -> image path or text The Inputs should match the needed slots in the Template

func ParseInputs

func ParseInputs(path string) (Inputs, error)

ParseInputs reads and parses the JSON Inputs file

type Output

type Output struct {
	Width  int    `json:"width,omitempty"`
	Height int    `json:"height,omitempty"`
	Format string `json:"format,omitempty"` // png, jpg, gif
}

Output defines the output image size and format

type ResizeMode

type ResizeMode string

ResizeMode options The option can be specified in the Slot struct as Mode field

const (
	ResizeModeFill  ResizeMode = "fill"
	ResizeModeFit   ResizeMode = "fit"
	ResizeModeCover ResizeMode = "cover"
)

fill - stretch the image to fit the slot fit - shrink the image to fit the slot cover - shrink the image to cover the slot

type Slot

type Slot struct {
	ID       string     `json:"id"`
	X        int        `json:"x"`
	Y        int        `json:"y"`
	Width    int        `json:"width"`
	Height   int        `json:"height"`
	Mask     string     `json:"mask,omitempty"`     // circle, rounded, or empty
	Radius   float64    `json:"radius,omitempty"`   // for rounded
	AnchorX  float64    `json:"anchor_x,omitempty"` // 0..1
	AnchorY  float64    `json:"anchor_y,omitempty"` // 0..1
	Mode     ResizeMode `json:"mode,omitempty"`     // ResizeMode: fill/fit/cover
	Opacity  float64    `json:"opacity,omitempty"`  // 0.0 - 1.0
	IsText   bool       `json:"is_text,omitempty"`
	TextOpts TextOpt    `json:"text_opts,omitempty"`
}

Slot defines either an image or text placement in the base image

func (Slot) DrawTextInto

func (slot Slot) DrawTextInto(dc *gg.Context, text string)

DrawTextInto draws text into the canvas using gg and supports wrapping and alignment Supports loading fonts from filesystem, URLs, system fonts, or embedded resources Font loading priority:

  1. If FontSource is specified, use that source explicitly
  2. If FontPath is provided, try filesystem
  3. If FontURL is provided, try downloading from URL
  4. If FontName is provided, try system fonts
  5. Use FONT_DIR/FONT_TTF environment variables
  6. Fall back to gg's builtin font

Note: dc must be initialized with the correct size before calling this function TODO: support vertical alignment TODO: support more text options like line spacing, etc.

type Template

type Template struct {
	// TemplateImage is the path to the base image to use for the template
	TemplateImage string `json:"template_image"`
	Output        Output `json:"output"`
	Slots         []Slot `json:"slots"`
}

Template defines the base image, Output options, and Slots

func ParseTemplate

func ParseTemplate(path string) (*Template, error)

ParseTemplate reads and parses the JSON Template file

type TextOpt

type TextOpt struct {
	FontPath   string  `json:"font_path,omitempty"`   // filesystem path
	FontName   string  `json:"font_name,omitempty"`   // system font name (e.g., "Arial", "Helvetica")
	FontSource string  `json:"font_source,omitempty"` // "file", "system", "url", "embedded", or "" for auto
	FontURL    string  `json:"font_url,omitempty"`    // URL to download font from
	FontSize   float64 `json:"font_size,omitempty"`
	Color      string  `json:"color,omitempty"`   // hex like #RRGGBB
	AlignX     string  `json:"align_x,omitempty"` // left, center, right
	AlignY     string  `json:"align_y,omitempty"` // top, middle, bottom
	Wrap       bool    `json:"wrap,omitempty"`
	MaxWidth   int     `json:"max_width,omitempty"` // px for wrapping
}

TextOpt defines text options for a Slot

Jump to

Keyboard shortcuts

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