ogcard

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package ogcard provides OpenGraph card image generation for ATCR.

Index

Constants

View Source
const (
	AlignLeft = iota
	AlignCenter
	AlignRight
)

Text alignment constants

View Source
const (
	// Card dimensions
	CardWidth  = 1200
	CardHeight = 630

	// Padding and sizing
	Padding    = 60
	AvatarSize = 180

	// Positioning offsets
	IconTopOffset    = 50 // Y offset from padding for icon
	TextGapAfterIcon = 40 // X gap between icon and text
	TextTopOffset    = 50 // Y offset from icon top for text baseline

	// Font sizes
	FontTitle       = 48.0
	FontDescription = 32.0
	FontStats       = 40.0 // Larger for visibility when scaled down
	FontBadge       = 32.0 // Larger for visibility when scaled down
	FontBranding    = 28.0

	// Spacing
	LineSpacingLarge = 65 // Gap after title
	LineSpacingSmall = 60 // Gap between description lines
	StatsIconGap     = 48 // Gap between stat icon and text
	StatsItemGap     = 60 // Gap between stat items
	BadgeGap         = 20 // Gap between badges
)

Layout constants for OG cards

Variables

View Source
var (
	ColorBackground  = color.RGBA{R: 22, G: 27, B: 34, A: 255}    // #161b22 - GitHub dark elevated
	ColorText        = color.RGBA{R: 230, G: 237, B: 243, A: 255} // #e6edf3 - Light text
	ColorMuted       = color.RGBA{R: 125, G: 133, B: 144, A: 255} // #7d8590 - Muted text
	ColorAccent      = color.RGBA{R: 47, G: 129, B: 247, A: 255}  // #2f81f7 - Blue accent
	ColorStar        = color.RGBA{R: 227, G: 179, B: 65, A: 255}  // #e3b341 - Star yellow
	ColorBadgeBg     = color.RGBA{R: 33, G: 38, B: 45, A: 255}    // #21262d - Badge background
	ColorBadgeAccent = color.RGBA{R: 31, G: 111, B: 235, A: 255}  // #1f6feb - Blue badge bg
)

Common colors

Functions

This section is empty.

Types

type Card

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

Card represents an OG image canvas

func NewCard

func NewCard() *Card

NewCard creates a new OG card with the standard 1200x630 dimensions

func NewCardWithSize

func NewCardWithSize(width, height int) *Card

NewCardWithSize creates a new OG card with custom dimensions

func (*Card) DrawAvatarOrPlaceholder

func (c *Card) DrawAvatarOrPlaceholder(url string, x, y, size int, letter string)

DrawAvatarOrPlaceholder draws a circular avatar from URL, falling back to placeholder

func (*Card) DrawBadge

func (c *Card) DrawBadge(text string, x, y int, fontSize float64, bgColor, textColor color.Color) int

DrawBadge draws a pill-shaped badge with text

func (*Card) DrawBranding

func (c *Card) DrawBranding()

DrawBranding draws "ATCR" in the bottom-right corner

func (*Card) DrawCircularImage

func (c *Card) DrawCircularImage(img image.Image, x, y, diameter int)

DrawCircularImage draws an image cropped to a circle

func (*Card) DrawIcon

func (c *Card) DrawIcon(name string, x, y, size int, col color.Color)

DrawIcon draws a Lucide icon at the specified position with the given size and color.

func (*Card) DrawImage

func (c *Card) DrawImage(img image.Image, x, y int)

DrawImage draws an image at the specified position

func (*Card) DrawPlaceholderCircle

func (c *Card) DrawPlaceholderCircle(x, y, diameter int, bgColor, textColor color.Color, letter string)

DrawPlaceholderCircle draws a colored circle with a letter

func (*Card) DrawRect

func (c *Card) DrawRect(x, y, w, h int, col color.Color)

DrawRect draws a filled rectangle

func (*Card) DrawRoundedRect

func (c *Card) DrawRoundedRect(x, y, w, h, radius int, col color.Color)

DrawRoundedRect draws a filled rounded rectangle

func (*Card) DrawStatWithIcon

func (c *Card) DrawStatWithIcon(icon string, text string, x, y int, iconColor, textColor color.Color) int

DrawStatWithIcon draws an icon + text stat and returns the next X position

func (*Card) DrawText

func (c *Card) DrawText(text string, x, y float64, size float64, col color.Color, align int, bold bool)

DrawText draws text at the specified position.

func (*Card) DrawTextWrapped

func (c *Card) DrawTextWrapped(text string, x, y float64, size float64, col color.Color, maxWidth int, bold bool) float64

DrawTextWrapped draws text with word wrapping within maxWidth Returns the Y position after the last line

func (*Card) EncodePNG

func (c *Card) EncodePNG(w io.Writer) error

EncodePNG encodes the card as PNG to the writer

func (*Card) FetchAndDrawCircularImage

func (c *Card) FetchAndDrawCircularImage(url string, x, y, diameter int) error

FetchAndDrawCircularImage fetches an image from URL and draws it as a circle

func (*Card) Fill

func (c *Card) Fill(col color.Color)

Fill fills the entire card with a solid color

func (*Card) MeasureText

func (c *Card) MeasureText(text string, size float64, bold bool) int

MeasureText returns the width of text in pixels

type Layout

type Layout struct {
	IconX    int
	IconY    int
	TextX    float64
	TextY    float64
	StatsY   int
	MaxWidth int // For text wrapping
}

Layout holds computed positions for a standard OG card layout

func StandardLayout

func StandardLayout() Layout

StandardLayout returns the standard OG card layout with computed positions

Jump to

Keyboard shortcuts

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