imgproc

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StageNameDownload      = "download"
	StageNameSaveOriginal  = "save-original"
	StageNameResize        = "resize"
	StageNameWatermark     = "watermark"
	StageNameSaveProcessed = "save-processed"
	StageNameUpload        = "upload"
)

Variables

This section is empty.

Functions

func BuildImageDownloadURL

func BuildImageDownloadURL(photoID string, width int, height int) string

BuildImageDownloadURL derives one concrete image download URL from the image ID and target dimensions.

func ConsumeProcessedImages

func ConsumeProcessedImages(images flx.Stream[ImageResult[[]byte]]) error

ConsumeProcessedImages drains the locally processed stream and logs one line per item plus one summary line.

func ConsumeUploadedImages

func ConsumeUploadedImages(results flx.Stream[ImageResult[string]]) error

ConsumeUploadedImages drains the upload result stream and logs one line per item plus one summary line.

func DownloadImageStage

func DownloadImageStage(
	sourceHTTPClient *http.Client,
	cfg PipelineConfig,
) func(context.Context, RemoteImage) ImageResult[[]byte]

DownloadImageStage returns the mapper used by the download step.

func DownloadImageWithRetry

func DownloadImageWithRetry(
	ctx context.Context,
	client *http.Client,
	image RemoteImage,
	cfg PipelineConfig,
) ([]byte, error)

DownloadImageWithRetry centralizes the retry policy shared by the examples.

func ExampleListEndpoint

func ExampleListEndpoint() string

ExampleListEndpoint returns the Picsum list endpoint used by the examples.

func ExampleUploadEndpoint

func ExampleUploadEndpoint() string

ExampleUploadEndpoint returns the local upload endpoint used by the examples.

func FormatDownloadRetryWarning

func FormatDownloadRetryWarning(imageURL string, event flx.RetryEvent) string

FormatDownloadRetryWarning keeps retry output aligned with the shared `kind=` logging contract.

func FormatItemError

func FormatItemError(err error) string

FormatItemError flattens wrapped and joined errors into one compact log line.

func ListExampleImages

func ListExampleImages(
	ctx context.Context,
	sourceHTTPClient *http.Client,
	cfg PipelineConfig,
) flx.Stream[RemoteImage]

ListExampleImages is the source stage shared by the image-processing examples. It pages the Picsum list endpoint lazily and emits work items as soon as they are discovered.

func NewSourceHTTPClient

func NewSourceHTTPClient() *http.Client

NewSourceHTTPClient returns the source-side HTTP client used by the examples.

func NewTargetHTTPClient

func NewTargetHTTPClient() *http.Client

NewTargetHTTPClient returns the optional upload-side HTTP client used by the examples.

func PostImage

func PostImage(
	ctx context.Context,
	client *http.Client,
	uploadEndpoint string,
	sourceURL string,
	imageBytes []byte,
) (string, error)

PostImage uploads transformed bytes to the optional target endpoint.

func SaveImageBytes

func SaveImageBytes(baseDir string, stage string, image ImageResult[[]byte]) error

SaveImageBytes writes one successful image result into a stage-specific folder.

func SaveLocalImageStage

func SaveLocalImageStage(
	baseDir string,
	stage string,
) func(context.Context, ImageResult[[]byte]) ImageResult[[]byte]

SaveLocalImageStage returns the mapper used by local persistence steps.

func TransformImageStage

func TransformImageStage(
	transform ImageTransformer,
) func(context.Context, ImageResult[[]byte]) ImageResult[[]byte]

TransformImageStage returns the mapper used by transform steps.

func UploadImageStage

func UploadImageStage(
	targetHTTPClient *http.Client,
	uploadEndpoint string,
) func(context.Context, ImageResult[[]byte]) ImageResult[string]

UploadImageStage returns the mapper used by the optional upload step.

Types

type ImageCatalogEntry

type ImageCatalogEntry struct {
	ID string `json:"id"`
}

ImageCatalogEntry models the minimal response shape this example family needs from the Picsum list endpoint.

func FetchImageCatalogPage

func FetchImageCatalogPage(
	ctx context.Context,
	client *http.Client,
	listEndpoint string,
	page int,
	limit int,
) ([]ImageCatalogEntry, error)

FetchImageCatalogPage requests one page of image metadata from the Picsum list endpoint.

type ImageResult

type ImageResult[T any] struct {
	ImageID   string
	SourceURL string
	Value     T
	Err       error
}

ImageResult carries either a successful value or an item-scoped failure for one image.

type ImageTransformer

type ImageTransformer func(ctx context.Context, sourceURL string, imageBytes []byte) ([]byte, error)

ImageTransformer describes one pure image-processing step.

func AddWatermarkText

func AddWatermarkText(text string) ImageTransformer

AddWatermarkText overlays a visible footer marker plus a tiny built-in bitmap text watermark.

func ResizeTo

func ResizeTo(width int, height int) ImageTransformer

ResizeTo returns a transformer that resizes images with a nearest-neighbor strategy.

type PipelineConfig

type PipelineConfig struct {
	ListEndpoint           string
	ListPageSize           int
	ListMaxPages           int
	LocalOutputDir         string
	DownloadWidth          int
	DownloadHeight         int
	DownloadWorkers        int
	DownloadRetryTimes     int
	DownloadRetryInterval  time.Duration
	DownloadAttemptTimeout time.Duration
	WatermarkWorkers       int
	UploadWorkers          int
	ResizeWidth            int
	ResizeHeight           int
	WatermarkText          string
	UploadEndpoint         string
}

PipelineConfig collects the knobs used by the image-processing examples. Zero or empty values fall back to small demo-friendly defaults.

func DefaultPipelineConfig

func DefaultPipelineConfig(outputDir string) PipelineConfig

DefaultPipelineConfig returns the baseline image-processing example config.

type RemoteImage

type RemoteImage struct {
	ID        string
	SourceURL string
}

RemoteImage is the payload emitted by the listing stage and consumed by the download stage.

Jump to

Keyboard shortcuts

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