resizer

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

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BatchResize

func BatchResize(ctx context.Context, req BatchResizeRequest, onProgress func(done, total int)) ([]string, error)

BatchResize processes images in SourceDir and exports resized variants to DestinationDir.

func CancelJob

func CancelJob(id string) bool

CancelJob cancels a resizer job.

func RegisterCancel

func RegisterCancel(id string, cancel context.CancelFunc)

RegisterCancel registers a cancel func.

func SetJob

func SetJob(id string, job *ResizerJob)

SetJob stores a resizer job by ID.

func StartCleanup

func StartCleanup(ctx context.Context, ttl time.Duration)

StartCleanup periodically cleans up expired jobs.

Types

type BatchResizeRequest

type BatchResizeRequest struct {
	SourceDir      string   `json:"source_dir"`
	DestinationDir string   `json:"destination_dir"`
	Presets        []string `json:"presets"`       // "web-optimized", "social-media", "thumbnails"
	CustomWidths   []int    `json:"custom_widths"` // e.g. [800, 1024]
	Quality        int      `json:"quality"`       // 1 - 100
}

BatchResizeRequest specifies source, destination, and selected presets.

type ResizeTarget

type ResizeTarget struct {
	Name   string `json:"name"`
	Width  int    `json:"width"`
	Height int    `json:"height"`
	Fit    bool   `json:"fit"`
}

ResizeTarget defines dimensions and fitting mode for a resized variant.

func ResolveTargets

func ResolveTargets(presets []string, customWidths []int) []ResizeTarget

ResolveTargets resolves list of ResizeTargets from presets and custom widths.

type ResizerJob

type ResizerJob struct {
	shared.Job
	SourceDir      string   `json:"source_dir"`
	DestinationDir string   `json:"destination_dir"`
	TotalImages    int      `json:"total_images"`
	ProcessedCount int      `json:"processed_count"`
	GeneratedFiles []string `json:"generated_files"`
	// contains filtered or unexported fields
}

ResizerJob tracks the background batch resizing job.

func GetJob

func GetJob(id string) (*ResizerJob, bool)

GetJob retrieves a resizer job by ID.

func (*ResizerJob) SetDone

func (j *ResizerJob) SetDone(files []string)

SetDone marks the job as done and stores generated files.

func (*ResizerJob) SetFailed

func (j *ResizerJob) SetFailed(errMsg string)

SetFailed marks the job as failed with an error message.

func (*ResizerJob) SetProgress

func (j *ResizerJob) SetProgress(done, total int)

SetProgress updates the job's processed count, total, and progress percentage.

func (*ResizerJob) Snapshot

func (j *ResizerJob) Snapshot() ResizerJob

Snapshot returns a thread-safe copy of the job's state.

Jump to

Keyboard shortcuts

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