Documentation
¶
Index ¶
- Variables
- func CacheKey(md5, previewSize string, percentage int) string
- func CreateThumbnail(rawData io.Reader, width, height int) (image.Image, error)
- func DelThumbs(ctx context.Context, file iteminfo.ExtendedFileInfo)
- func GeneratePreview(ctx context.Context, file iteminfo.ExtendedFileInfo, ...) ([]byte, error)
- func GeneratePreviewWithMD5(ctx context.Context, file iteminfo.ExtendedFileInfo, ...) ([]byte, error)
- func GetPreviewForFile(ctx context.Context, file iteminfo.ExtendedFileInfo, previewSize, url string, ...) ([]byte, error)
- func ImageFitsPreviewSize(imgWidth, imgHeight int, previewSize string) bool
- func ReadImageFileDimensions(path string) (int, int, error)
- func ShouldServeOriginalImage(path, previewSize string) bool
- func StartPreviewGenerator(concurrencyLimit int, cacheDir string) error
- type Format
- type MemoryTracker
- type Quality
- type ResizeMode
- type ResizeOptions
- type Service
- func (s *Service) CreatePreview(ctx context.Context, reader io.Reader, fileSize int64, options ResizeOptions) ([]byte, error)
- func (s *Service) FormatFromExtension(ext string) (Format, error)
- func (s *Service) GenerateImageFromDoc(ctx context.Context, file iteminfo.ExtendedFileInfo, tempFilePath string, ...) ([]byte, error)
- func (s *Service) GenerateOfficePreview(ctx context.Context, filetype, key, title, url string) ([]byte, error)
- func (s *Service) GenerateVideoPreview(ctx context.Context, videoPath string, percentageSeek int) ([]byte, error)
- func (s *Service) Resize(ctx context.Context, in io.Reader, out io.Writer, opts ResizeOptions) error
- func (s *Service) ResizeWithSize(ctx context.Context, in io.Reader, out io.Writer, fileSize int64, ...) error
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func CreateThumbnail ¶
CreateThumbnail decodes an image and creates a fixed-size thumbnail.
func GeneratePreview ¶
func GeneratePreviewWithMD5 ¶
func GetPreviewForFile ¶
func ImageFitsPreviewSize ¶
ImageFitsPreviewSize reports whether both image dimensions are within the preview bounds.
func ReadImageFileDimensions ¶
ReadImageFileDimensions reads image width and height without decoding the full image.
func ShouldServeOriginalImage ¶
ShouldServeOriginalImage reports whether an on-disk image is already within preview bounds.
func StartPreviewGenerator ¶
Types ¶
type Format ¶
type Format int
Format is an image file format.
ENUM( jpeg png gif tiff bmp heic webp pbm pgm ppm pam )
const ( // FormatJpeg is a Format of type Jpeg FormatJpeg Format = iota // FormatPng is a Format of type Png FormatPng // FormatGif is a Format of type Gif FormatGif // FormatTiff is a Format of type Tiff FormatTiff // FormatBmp is a Format of type Bmp FormatBmp // FormatHeic is a Format of type Heic FormatHeic // FormatWebp is a Format of type Webp FormatWebp // FormatPbm is a Format of type Pbm FormatPbm // FormatPgm is a Format of type Pgm FormatPgm // FormatPpm is a Format of type Ppm FormatPpm // FormatPam is a Format of type Pam FormatPam )
func ParseFormat ¶
ParseFormat attempts to convert a string to a Format
func (Format) MarshalText ¶
MarshalText implements the text marshaller method
func (*Format) UnmarshalText ¶
UnmarshalText implements the text unmarshaller method
type MemoryTracker ¶
type MemoryTracker struct {
// contains filtered or unexported fields
}
MemoryTracker wraps the existing FFmpegService to add memory tracking
func NewMemoryTracker ¶
func NewMemoryTracker(maxConcurrent int, maxMemoryMB int) *MemoryTracker
NewMemoryTracker creates a memory-aware concurrency limiter
func (*MemoryTracker) Acquire ¶
func (mt *MemoryTracker) Acquire(ctx context.Context, estimatedBytes int64) error
Acquire waits to acquire resources
func (*MemoryTracker) GetMemoryUsageMB ¶
func (mt *MemoryTracker) GetMemoryUsageMB() int64
GetMemoryUsageMB returns current memory usage in MB
func (*MemoryTracker) Release ¶
func (mt *MemoryTracker) Release(estimatedBytes int64)
Release frees up resources
func (*MemoryTracker) TryAcquire ¶
func (mt *MemoryTracker) TryAcquire(ctx context.Context, estimatedBytes int64) bool
TryAcquire attempts to acquire resources for processing an image Returns false if memory limit would be exceeded
type Quality ¶
type Quality int
ENUM( high medium low )
func ParseQuality ¶
ParseQuality attempts to convert a string to a Quality
func (Quality) MarshalText ¶
MarshalText implements the text marshaller method
func (*Quality) UnmarshalText ¶
UnmarshalText implements the text unmarshaller method
type ResizeMode ¶
type ResizeMode int
ENUM( fit fill )
const ( // ResizeModeFit is a ResizeMode of type Fit ResizeModeFit ResizeMode = iota // ResizeModeFill is a ResizeMode of type Fill ResizeModeFill )
func ParseResizeMode ¶
func ParseResizeMode(name string) (ResizeMode, error)
ParseResizeMode attempts to convert a string to a ResizeMode
func (ResizeMode) MarshalText ¶
func (x ResizeMode) MarshalText() ([]byte, error)
MarshalText implements the text marshaller method
func (*ResizeMode) Scan ¶
func (x *ResizeMode) Scan(value interface{}) error
Scan implements the Scanner interface.
func (ResizeMode) String ¶
func (x ResizeMode) String() string
String implements the Stringer interface.
func (*ResizeMode) UnmarshalText ¶
func (x *ResizeMode) UnmarshalText(text []byte) error
UnmarshalText implements the text unmarshaller method
type ResizeOptions ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func GetService ¶
func GetService() *Service
GetService returns the preview service instance (can be nil if not started)
func NewPreviewGenerator ¶
Calculate split between small and large imaging library processors Distribution formula:
1 processor: single image processor for all sizes 2 processors: 1 large, 1 small 3-6 processors: 2 large, rest small 7+ processors: 3 large, rest small
func (*Service) CreatePreview ¶
func (s *Service) CreatePreview(ctx context.Context, reader io.Reader, fileSize int64, options ResizeOptions) ([]byte, error)
CreatePreview resizes an image from a reader with the given options
func (*Service) FormatFromExtension ¶
func (*Service) GenerateImageFromDoc ¶
func (*Service) GenerateOfficePreview ¶
func (s *Service) GenerateOfficePreview(ctx context.Context, filetype, key, title, url string) ([]byte, error)
GenerateOfficePreview generates a preview for an office document using OnlyOffice. Note: Global image processor semaphore is acquired at GeneratePreviewWithMD5 level
func (*Service) GenerateVideoPreview ¶
func (s *Service) GenerateVideoPreview(ctx context.Context, videoPath string, percentageSeek int) ([]byte, error)
GenerateVideoPreview generates a single preview image from a video using ffmpeg. videoPath: path to the input video file. percentageSeek: percentage of video duration to seek to (0–100). Returns: JPEG image bytes.
func (*Service) ResizeWithSize ¶
func (s *Service) ResizeWithSize(ctx context.Context, in io.Reader, out io.Writer, fileSize int64, opts ResizeOptions) error
ResizeWithSize resizes an image with file size information for appropriate semaphore selection. Resize runs synchronously so the image semaphore accurately bounds concurrent CPU work. A detached goroutine would return on ctx cancellation while still decoding/resizing, defeating the semaphore and piling up orphaned work that causes preview timeouts under load.