preview

package
v0.0.0-...-642333e Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2025 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupportedFormat = errors.New("preview is not available for provided file format")
	ErrUnsupportedMedia  = errors.New("unsupported media type")
)

Functions

func AvailablePreview

func AvailablePreview(file iteminfo.ExtendedFileInfo) bool

func CacheKey

func CacheKey(realPath, previewSize string, modTime time.Time, percentage int) string

func CheckValidFFmpeg

func CheckValidFFmpeg(path string) (string, error)

CheckValidFFmpeg checks for a valid ffmpeg executable. If a path is provided, it looks there. Otherwise, it searches the system's PATH.

func CheckValidFFprobe

func CheckValidFFprobe(path string) (string, error)

CheckValidFFprobe checks for a valid ffprobe executable. If a path is provided, it looks there. Otherwise, it searches the system's PATH.

func CreateThumbnail

func CreateThumbnail(rawData io.Reader, width, height int) (image.Image, error)

CreateThumbnail decodes an image and creates a fixed-size thumbnail.

func DelThumbs

func DelThumbs(ctx context.Context, file iteminfo.ExtendedFileInfo)

func GeneratePreview

func GeneratePreview(file iteminfo.ExtendedFileInfo, previewSize, officeUrl string, seekPercentage int) ([]byte, error)

func GetPreviewForFile

func GetPreviewForFile(file iteminfo.ExtendedFileInfo, previewSize, url string, seekPercentage int) ([]byte, error)

func StartPreviewGenerator

func StartPreviewGenerator(concurrencyLimit int, ffmpegPath, cacheDir string) error

Types

type Format

type Format int

Format is an image file format.

ENUM( jpeg png gif tiff bmp )

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
)

func ParseFormat

func ParseFormat(name string) (Format, error)

ParseFormat attempts to convert a string to a Format

func (Format) MarshalText

func (x Format) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method

func (*Format) Scan

func (x *Format) Scan(value interface{}) error

Scan implements the Scanner interface.

func (Format) String

func (x Format) String() string

String implements the Stringer interface.

func (*Format) UnmarshalText

func (x *Format) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method

func (Format) Value

func (x Format) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Option

type Option func(*resizeConfig)

func WithFormat

func WithFormat(format Format) Option

func WithMode

func WithMode(mode ResizeMode) Option

func WithQuality

func WithQuality(quality Quality) Option

type Quality

type Quality int

ENUM( high medium low )

const (
	// QualityHigh is a Quality of type High
	QualityHigh Quality = iota
	// QualityMedium is a Quality of type Medium
	QualityMedium
	// QualityLow is a Quality of type Low
	QualityLow
)

func ParseQuality

func ParseQuality(name string) (Quality, error)

ParseQuality attempts to convert a string to a Quality

func (Quality) MarshalText

func (x Quality) MarshalText() ([]byte, error)

MarshalText implements the text marshaller method

func (*Quality) Scan

func (x *Quality) Scan(value interface{}) error

Scan implements the Scanner interface.

func (Quality) String

func (x Quality) String() string

String implements the Stringer interface.

func (*Quality) UnmarshalText

func (x *Quality) UnmarshalText(text []byte) error

UnmarshalText implements the text unmarshaller method

func (Quality) Value

func (x Quality) Value() (driver.Value, error)

Value implements the driver Valuer interface.

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

func (ResizeMode) Value

func (x ResizeMode) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Service

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

func NewPreviewGenerator

func NewPreviewGenerator(concurrencyLimit int, ffmpegPath string, cacheDir string) *Service

func (*Service) CreatePreview

func (s *Service) CreatePreview(data []byte, previewSize string) ([]byte, error)

func (*Service) FormatFromExtension

func (s *Service) FormatFromExtension(ext string) (Format, error)

func (*Service) GenerateImageFromDoc

func (s *Service) GenerateImageFromDoc(file iteminfo.ExtendedFileInfo, tempFilePath string, pageNumber int) ([]byte, error)

func (*Service) GenerateOfficePreview

func (s *Service) GenerateOfficePreview(filetype, key, title, url string) ([]byte, error)

GenerateOfficePreview generates a preview for an office document using OnlyOffice.

func (*Service) GenerateVideoPreview

func (s *Service) GenerateVideoPreview(videoPath, outputPath string, percentageSeek int) ([]byte, error)

GenerateVideoPreview generates a single preview image from a video using ffmpeg. videoPath: path to the input video file. outputPath: path where the generated preview image will be saved (e.g., "/tmp/preview.jpg"). seekTime: how many seconds into the video to seek before capturing the frame.

func (*Service) Resize

func (s *Service) Resize(in io.Reader, width, height int, out io.Writer, options ...Option) error

Jump to

Keyboard shortcuts

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