tmemes

package module
v0.0.0-...-993899d Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

README

tmemes: putting the meme in TS

This bit of fun was brought to you through the amazing power of Tailscale, and the collaborative efforts of

  • Maisem Ali: "I think we need memegen"
  • M. J. Fromberger: "why did I not think of that"
  • Jenny Zhang: "ok i’m finally in front of a computer, can I go write some css"
  • Salman Aljammaz: (quietly moves heaven and earth inside a <canvas>)
  • Shayne Sweeney: "Would I be stepping on toes if I built a Slack bot?"

together with a lovely and inspirational crew of supporters. There's lots more fun still to be had, so if you want to jump in, read on! There is also a wishlist of TODO items at the bottom.


Synopsis

tmemes is a web app built mainly in Go and running on tsnet. This is a very terse description of how it all works.

  • The server is tmemes, a standalone Go binary using tsnet. Run

    TS_AUTHKEY=$KEY go run ./tmemes
    

    to start the server. Make sure your tailnet ACL allows access to this node, and you should be able to visit http://tmemes in the browser.

  • The server "database" is a directory of files. Use --data-dir to set the location; it defaults to /tmp/tmemes.

  • Terminology:

    • Template: A base image that can be decorated with text.
    • Macro: An image macro combining a template and a text overlay.
    • Text overlay: Lines of text with position and typographical info.

    Types are in types.go.

  • The data directory contains an index.db which is a SQLite database (schema in store/schema.sql), plus various other directories of image content:

    • templates are the template images.
    • macros are cached macros (re-generated on the fly as needed).
    • static are some static assets used by the macro generator (esp. fonts).

    The store package kinda provides a thin wrapper around these data.

  • UI elements are generated by Go HTML templates in tmemes/ui. These are statically embedded into the server and served by the handlers.

  • Static assets needed by the UI are stored in tmemes/static. These are served via /static/ paths in the server mux.


Documentation

Overview

Package tmemes defines a meme generator, putting the meme in TS.

This package defines shared data types used throughout the service.

Index

Constants

View Source
const MaxContextLinks = 3

MaxContextLinks is the maximum number of context links permitted on a macro.

Variables

This section is empty.

Functions

This section is empty.

Types

type Area

type Area struct {
	X     float64 `json:"x"`               // x offset of anchor as a fraction 0..1 of width
	Y     float64 `json:"y"`               // y offset of anchor as a fraciton 0..1 of height
	Width float64 `json:"width,omitempty"` // width of text box as a fraction of image width

	// If true, adjust the effective coordinates for each frame by interpolating
	// the distance between the given X, Y and the X, Y of the next area in
	// sequence, when rendering multiple frames.
	//
	// This is ignored when rendering on a single-frame template.
	Tween bool `json:"tween,omitempty"`
}

An Area defines a region of an image where text is placed. Each area has an anchor point, relative to the top-left of the image, and a target width and height as fractions of the image size. Text drawn within an area should be scaled so that the resulting box does not exceed those dimensions.

func (Area) ValidForCreate

func (a Area) ValidForCreate() error

ValidForCreate reports whether a is valid for creation of a new macro.

type Areas

type Areas []Area

Areas is a wrapper for a slice of Area values that optionally decodes from JSON as either a single Area object or an array of Area values. A length-1 Areas encodes as a plain object.

func (Areas) MarshalJSON

func (a Areas) MarshalJSON() ([]byte, error)

func (*Areas) UnmarshalJSON

func (a *Areas) UnmarshalJSON(data []byte) error

type Color

type Color [3]float64

A Color represents an RGB color encoded as hex. It supports encoding in JSON as a string, allowing "#xxxxxx" or "#xxx" format (the "#" is optional).

func MustColor

func MustColor(s string) Color

MustColor constructs a color from a known color name or hex specification #xxx or #xxxxxx. It panics if s does not correspond to a valid color.

func (Color) B

func (c Color) B() float64

func (Color) G

func (c Color) G() float64

func (Color) MarshalText

func (c Color) MarshalText() ([]byte, error)

func (Color) R

func (c Color) R() float64

func (*Color) UnmarshalText

func (c *Color) UnmarshalText(data []byte) error
type ContextLink struct {
	URL  string `json:"url"`            // required
	Text string `json:"text,omitempty"` // optional
}

ContextLink is a link to explain the context of a macro.

type ContextRequest

type ContextRequest struct {
	// Action specifies what to do with the context links on the macro.
	// The options are "add", "clear", and "remove".
	Action string `json:"action"`

	// Link specifies the link to add or remove. At least the URL of the link
	// must be specified unless Action is "clear".
	Link ContextLink `json:"link"`
}

ContextRequest is the payload for the /api/context handler.

type Macro

type Macro struct {
	ID          int            `json:"id"`
	TemplateID  int            `json:"templateID"`
	Creator     tailcfg.UserID `json:"creator,omitempty"` // -1 for anon
	CreatedAt   time.Time      `json:"createdAt"`
	TextOverlay []TextLine     `json:"textOverlay"`
	ContextLink []ContextLink  `json:"contextLink,omitempty"`

	Upvotes   int `json:"upvotes,omitempty"`
	Downvotes int `json:"downvotes,omitempty"`
}

A Macro combines a Template with some text. Macros can be cached by their ID, or re-rendered on-demand.

func (*Macro) ValidForCreate

func (m *Macro) ValidForCreate() error

ValidForCreate reports whether m is valid for the creation of a new macro.

type Template

type Template struct {
	ID        int            `json:"id"`     // assigned by the server
	Path      string         `json:"path"`   // path of image file
	Width     int            `json:"width"`  // image width
	Height    int            `json:"height"` // image height
	Name      string         `json:"name"`   // descriptive label
	Creator   tailcfg.UserID `json:"creator"`
	CreatedAt time.Time      `json:"createdAt"`
	Areas     []Area         `json:"areas,omitempty"` // optional predefined areas
	Hidden    bool           `json:"hidden,omitempty"`
}

A Template defines a base template for an image macro.

type TextLine

type TextLine struct {
	Text        string `json:"text"`
	Color       Color  `json:"color"`
	StrokeColor Color  `json:"strokeColor"`

	// The location(s) where the text should be drawn, it must be non-empty.
	// For a single-frame image, only the first entry is used.
	//
	// For a multiple-frame image, the locations are applied cyclically to the
	// frames of the image. Each area occupies an equal fraction of the frames,
	// for example if there are 8 frames and 2 areas, each area is mapped to 4
	// frames (Field[0] to frames 0, 1, 2, 3; Field[1] to frames 4, 5, 6, 7).
	Field Areas `json:"field"`

	// The first point in a multi-frame image where this text should be visible,
	// as a fraction (0..1) of the total frames of the image. For example, in an
	// image with 16 frames, 0.25 represents 4 frames.
	//
	// if > 0, do not show the text line before this frame fraction.
	// If = 0, show the text beginning at the first frame.
	Start float64 `json:"start,omitempty"` // 0..1

	// The last point in a multi-frame image where this text should be visible,
	// as a fraction (0..1) of the total frames of the image. For example, in an
	// image with 10 frames, 0.5 represents 5 frames.
	//
	// If > Start, hide the text after this frame fraction.
	// Otherwise, do not hide the text after the start index.
	End float64 `json:"end,omitempty"` // 0..1

}

A TextLine is a single line of text with an optional alignment.

func (TextLine) ValidForCreate

func (t TextLine) ValidForCreate() error

ValidForCreate reports whether t is valid for creation of a macro.

Directories

Path Synopsis
cmd
tmemes
Program tmemes is an image macro server that runs as a node on a tailnet.
Program tmemes is an image macro server that runs as a node on a tailnet.
Package memedraw draws text on a tempate.
Package memedraw draws text on a tempate.
Package store implements a data store for memes.
Package store implements a data store for memes.

Jump to

Keyboard shortcuts

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