thumbnail

package
v0.0.0-...-de1cc99 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package thumbnail provides image thumbnail generation and caching.

Index

Constants

This section is empty.

Variables

View Source
var Presets = map[string]Preset{
	"xw11": {Width: 26, Height: 26},
	"xw27": {Width: 28, Height: 38},
	"xw22": {Width: 36, Height: 24},
	"xw12": {Width: 52, Height: 35},
	"xw28": {Width: 64, Height: 43},
	"xw23": {Width: 72, Height: 48},
	"xw14": {Width: 160, Height: 107},
	"xw17": {Width: 160, Height: 120},
	"xw10": {Width: 160, Height: 120},
	"xw29": {Width: 150, Height: 150},
	"xw24": {Width: 168, Height: 112},
	"xw20": {Width: 170, Height: 113},
	"xw15": {Width: 206, Height: 137},
	"xw19": {Width: 206, Height: 206},
	"xw26": {Width: 270, Height: 365},
	"xw18": {Width: 305, Height: 230},
	"xw13": {Width: 320, Height: 213},
	"xw16": {Width: 320, Height: 240},
	"xw25": {Width: 336, Height: 224},
	"xw21": {Width: 340, Height: 226},
	"xw2":  {Width: 1000, Height: 667},
	"xw1":  {Width: 0, Height: 0},
}

Presets maps preset names to dimensions as defined in API specification.

Functions

func IsSupportedFormat

func IsSupportedFormat(filename string) bool

IsSupportedFormat checks if the file extension indicates a supported image format.

Types

type Generator

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

Generator creates and caches image thumbnails.

func NewGenerator

func NewGenerator(cacheDir string) (*Generator, error)

NewGenerator creates a new thumbnail generator with the specified cache directory. If cacheDir is empty, thumbnails are generated on-the-fly without caching.

func (*Generator) Generate

func (g *Generator) Generate(srcFile *os.File, hash string, preset Preset) (*Result, error)

Generate creates a thumbnail for the given image file at the specified preset size. Returns the thumbnail data and content type.

type Preset

type Preset struct {
	Width  int
	Height int
}

Preset defines thumbnail dimensions.

func GetPreset

func GetPreset(name string) *Preset

GetPreset returns the preset for the given name, or nil if not found.

func (Preset) IsOriginal

func (p Preset) IsOriginal() bool

IsOriginal returns true if the preset represents original size.

type Result

type Result struct {
	Data        []byte
	ContentType string
}

Result holds the generated thumbnail data.

Jump to

Keyboard shortcuts

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