Documentation
¶
Overview ¶
Package thumbnail provides image thumbnail generation and caching
Index ¶
- Variables
- func IsSupportedImage(filename string) bool
- type Service
- func (s *Service) CacheStats(ctx context.Context) (count int, size int64, err error)
- func (s *Service) CleanCache(ctx context.Context, maxAge time.Duration) (int, error)
- func (s *Service) GetThumbnail(ctx context.Context, filePath string, size Size, reader io.ReadSeeker) ([]byte, error)
- func (s *Service) GetThumbnailVersioned(ctx context.Context, filePath, cacheVersion string, size Size, ...) ([]byte, error)
- func (s *Service) InvalidateCache(filePath string) error
- func (s *Service) Wait()
- type Size
Constants ¶
This section is empty.
Variables ¶
var ErrThumbnailSourceTooLarge = errors.New("source image too large for thumbnail generation")
var SizeDimensions = map[Size]int{ SizeSmall: 150, SizeMedium: 300, SizeLarge: 600, }
SizeDimensions maps size presets to pixel dimensions
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 ¶
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 ¶
NewService creates a new thumbnail service
func (*Service) CacheStats ¶
CacheStats returns cache statistics
func (*Service) CleanCache ¶
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 ¶
InvalidateCache removes cached thumbnails for a specific file