layout

package
v0.110.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package layout lays an ad's words over its picture: the headline, a second line, a button and the brand's logo, in any shape. The picture itself carries no text, so the words can change and the ad can be made in another size without making (and paying for) a new picture.

Index

Constants

View Source
const (
	MinWidth = 240
	MaxWidth = 2160
)

Limits on what is drawn.

Variables

This section is empty.

Functions

func Encode

func Encode(m image.Image, format string) ([]byte, string, error)

Encode writes a rendered ad as JPEG (format "jpeg") or PNG.

func HexColor

func HexColor(s string) (color.NRGBA, bool)

HexColor reads #rgb or #rrggbb.

func Render

func Render(ad Ad, shape float64, width int) (*image.NRGBA, error)

Render draws the ad in the given shape (width over height), width pixels wide.

func Shape

func Shape(size string) (float64, bool)

Shape reads a size such as 4:5 as width over height. Shapes more than three times as wide as tall, or as tall as wide, are refused.

Types

type Ad struct {
	// Picture fills the whole ad, cropped around its middle.
	Picture image.Image
	Logo image.Image
	// Headline, Subline and CTA are the words; any may be empty.
	Headline, Subline, CTA string
	// Font is a TrueType or OpenType font for every word; nil, or one
	// that can't be read, uses the built-in one.
	Font []byte
	// Accent colours the button; nil gives a white one.
	Accent *color.NRGBA
}

Ad is what goes on one picture.

Jump to

Keyboard shortcuts

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