Documentation
¶
Index ¶
- func ApplyOpacity(img image.Image, opacity float64) image.Image
- func ImageDriver(templatePath string, inputsPath string, outputPath string) error
- func LoadImageFromFile(path string) (image.Image, error)
- func MakeMask(maskType string, w, h int, radius float64) *image.Alpha
- func ResizeImage(src image.Image, dstW, dstH int, mode ResizeMode) image.Image
- func SaveImageToFile(img image.Image, outpath, format string) error
- type Inputs
- type Output
- type ResizeMode
- type Slot
- type Template
- type TextOpt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyOpacity ¶
ApplyOpacity multiplies alpha channel by opacity
func ImageDriver ¶
func LoadImageFromFile ¶
LoadImageFromFile decodes common image formats
func ResizeImage ¶
ResizeImage implements fill/fit/cover.
Types ¶
type Inputs ¶
Inputs map slotID -> image path or text The Inputs should match the needed slots in the Template
func ParseInputs ¶
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 ¶
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:
- If FontSource is specified, use that source explicitly
- If FontPath is provided, try filesystem
- If FontURL is provided, try downloading from URL
- If FontName is provided, try system fonts
- Use FONT_DIR/FONT_TTF environment variables
- 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 ¶
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