thumbnail

package
v0.0.0-...-bfdad2a Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Overview

Package thumbnail provides image thumbnail generation and caching

Index

Constants

This section is empty.

Variables

View Source
var ErrThumbnailSourceTooLarge = errors.New("source image too large for thumbnail generation")
View Source
var SizeDimensions = map[Size]int{
	SizeSmall:  150,
	SizeMedium: 300,
	SizeLarge:  600,
}

SizeDimensions maps size presets to pixel dimensions

View Source
var SupportedExtensions = map[string]bool{
	".jpg":  true,
	".jpeg": true,
	".png":  true,
	".gif":  true,
	".webp": true,
	".bmp":  true,
	".tiff": true,
	".tif":  true,
}

SupportedExtensions lists image extensions that can be thumbnailed

Functions

func IsSupportedImage

func IsSupportedImage(filename string) bool

IsSupportedImage checks if a file extension is supported for thumbnail generation

Types

type Service

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

Service provides thumbnail generation and caching

func NewService

func NewService(cacheDir string) (*Service, error)

NewService creates a new thumbnail service

func (*Service) CacheStats

func (s *Service) CacheStats(ctx context.Context) (count int, size int64, err error)

CacheStats returns cache statistics

func (*Service) CleanCache

func (s *Service) CleanCache(ctx context.Context, maxAge time.Duration) (int, error)

CleanCache removes cached thumbnails older than maxAge

func (*Service) GetThumbnail

func (s *Service) GetThumbnail(ctx context.Context, filePath string, size Size, reader io.ReadSeeker) ([]byte, error)

GetThumbnail returns a thumbnail for the given file, generating if needed

func (*Service) GetThumbnailVersioned

func (s *Service) GetThumbnailVersioned(ctx context.Context, filePath, cacheVersion string, size Size, reader io.ReadSeeker) ([]byte, error)

GetThumbnailVersioned returns a thumbnail keyed by both file path and a caller-provided content signature so stale cache entries are bypassed when the underlying file content changes.

func (*Service) InvalidateCache

func (s *Service) InvalidateCache(filePath string) error

InvalidateCache removes cached thumbnails for a specific file

func (*Service) Wait

func (s *Service) Wait()

Wait blocks until background cache persistence work has finished.

type Size

type Size string

Size represents thumbnail size preset

const (
	SizeSmall  Size = "small"  // 150x150
	SizeMedium Size = "medium" // 300x300
	SizeLarge  Size = "large"  // 600x600
)

Jump to

Keyboard shortcuts

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