Help us shape the future of Go! Take the 2026 Go Developer Survey

artwork

package
v0.2.17 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: GPL-3.0 Imports: 34 Imported by: 0

Documentation

Overview

Package artwork serves and makes Ether's artwork: a caching proxy for TMDB images (memory LRU over a disk cache) and a pure-Go poster generator for collections (collage and backdrop treatments with the title set in the Go fonts).

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidPath rejects anything that is not a TMDB image path.
	ErrInvalidPath = errors.New("artwork: not a TMDB image path")
	// ErrNotFound means the image does not exist upstream.
	ErrNotFound = errors.New("artwork: image not found")
)

Functions

func Compose

func Compose(req PosterRequest, posters, backdrops []image.Image) *image.RGBA

Compose draws a poster from already-decoded images. It is pure, so tests can check its output without a network.

collage   2×2 (4+ posters) or 3×2 (6 posters) tiles under a gradient
backdrop  a member backdrop cropped to portrait with a title treatment
auto      collage with 4+ posters, else backdrop, else a single poster,
          else a typographic poster in the accent colour

func Size

func Size(w int) string

Size picks the smallest TMDB size at least w wide ("original" for 0, capped at w1280 otherwise).

func ValidPath

func ValidPath(p string) bool

ValidPath reports whether p is a TMDB image path such as "/abc123.jpg": a single file name, so it can never traverse or address another host.

Types

type ImageSource

type ImageSource interface {
	Get(ctx context.Context, path string, w int) ([]byte, string, error)
}

ImageSource loads TMDB images; *Images satisfies it.

type Images

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

Images is a caching TMDB image store. Concurrent requests for the same image share one fetch. Safe for concurrent use.

func NewImages

func NewImages(o ImagesOptions) *Images

NewImages creates an image store.

func (*Images) Get

func (im *Images) Get(ctx context.Context, path string, w int) ([]byte, string, error)

Get returns a TMDB image at the smallest size covering width w.

func (*Images) GetURL

func (im *Images) GetURL(ctx context.Context, rawURL string) ([]byte, string, error)

GetURL fetches an owner-supplied image URL (custom collection art). Only http(s) URLs to images are accepted.

type ImagesOptions

type ImagesOptions struct {
	// Dir is the disk cache directory ("" = memory only).
	Dir string
	// MemoryBytes bounds the in-memory LRU (default 64 MiB).
	MemoryBytes int64
	// DiskBytes bounds the disk cache (default 512 MiB).
	DiskBytes int64
	// HTTPClient fetches images (default: 20 s timeout).
	HTTPClient *http.Client
	// ImageURL builds TMDB URLs (default image.tmdb.org).
	ImageURL core.ImageURLFunc
	Logger   *slog.Logger
}

ImagesOptions configure an image store.

type PosterRequest

type PosterRequest struct {
	Title    string   `json:"title"`
	Subtitle string   `json:"subtitle,omitempty"` // small caps line above the title, e.g. "24 FILMS"
	Mode     string   `json:"mode"`               // auto | collage | backdrop
	Accent   string   `json:"accent,omitempty"`   // "#rrggbb"; derived from the artwork when empty
	Posters  []string `json:"posters,omitempty"`  // member poster paths (up to 6 used)
	// Backdrops are member backdrop paths (the first that loads is used).
	Backdrops []string `json:"backdrops,omitempty"`
	Width     int      `json:"width"` // output width; height is 1.5×
}

PosterRequest describes a collection poster.

func (PosterRequest) String

func (r PosterRequest) String() string

String describes a request (logs).

type Renderer

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

Renderer makes collection posters and caches them on disk, keyed by everything that affects the pixels (title, mode, accent, members, size).

func NewRenderer

func NewRenderer(src ImageSource, dir string, log *slog.Logger) *Renderer

NewRenderer creates a renderer. dir "" disables the disk cache.

func (*Renderer) Poster

func (r *Renderer) Poster(ctx context.Context, req PosterRequest) ([]byte, string, error)

Poster returns a JPEG poster for req.

Jump to

Keyboard shortcuts

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