processor

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Thumbnail = ResizeOptions{Width: 245, Height: 156, Quality: 80}
	Small     = ResizeOptions{Width: 500, Height: 500, Quality: 85}
	Medium    = ResizeOptions{Width: 750, Height: 750, Quality: 85}
	Large     = ResizeOptions{Width: 1000, Height: 1000, Quality: 90}
)

Standard sizes

Functions

func GenerateThumbnail

func GenerateThumbnail(data []byte, maxSize int) ([]byte, error)

GenerateThumbnail 生成缩略图

func GetImageInfo

func GetImageInfo(data []byte) (width, height int, format string, err error)

GetImageInfo 获取图片信息

Types

type CompressStep

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

CompressStep 压缩步骤

func (CompressStep) Process

func (s CompressStep) Process(ctx context.Context, data []byte) ([]byte, error)

CompressStep 实现

type ExtractMetadataStep

type ExtractMetadataStep struct{}

ExtractMetadataStep 提取元数据步骤

func (ExtractMetadataStep) Process

func (s ExtractMetadataStep) Process(ctx context.Context, data []byte) ([]byte, error)

ExtractMetadataStep 实现

type FormatStep

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

FormatStep 格式转换步骤

func (FormatStep) Process

func (s FormatStep) Process(ctx context.Context, data []byte) ([]byte, error)

FormatStep 实现

type GrayscaleStep

type GrayscaleStep struct{}

GrayscaleStep 灰度转换步骤

func (GrayscaleStep) Process

func (s GrayscaleStep) Process(ctx context.Context, data []byte) ([]byte, error)

GrayscaleStep 实现

type ImageConfig

type ImageConfig struct {
	MaxWidth  int    `json:"max_width"`
	MaxHeight int    `json:"max_height"`
	Quality   int    `json:"quality"`   // 1-100
	Format    string `json:"format"`    // jpeg, png, webp
	Watermark string `json:"watermark"` // 水印文字
	Compress  bool   `json:"compress"`  // 是否压缩
	Grayscale bool   `json:"grayscale"` // 是否灰度
}

ImageConfig 图片配置

type ImageProcessor

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

ImageProcessor 图片处理器

func NewImageProcessor

func NewImageProcessor(config ImageConfig) *ImageProcessor

NewImageProcessor 创建图片处理器

func (*ImageProcessor) GetDimensions

func (p *ImageProcessor) GetDimensions(reader io.Reader) (int, int, error)

GetDimensions 获取图片尺寸(实现 Resizer 接口)

func (*ImageProcessor) Process

func (p *ImageProcessor) Process(ctx context.Context, input []byte) ([]byte, error)

Process 处理单个图片

func (*ImageProcessor) ProcessFromFile

func (p *ImageProcessor) ProcessFromFile(ctx context.Context, filePath string) ([]byte, error)

ProcessFromFile 从文件处理

func (*ImageProcessor) ProcessFromReader

func (p *ImageProcessor) ProcessFromReader(ctx context.Context, reader io.Reader) ([]byte, error)

ProcessFromReader 从 Reader 处理

func (*ImageProcessor) Resize

func (p *ImageProcessor) Resize(reader io.Reader, width, height uint) (io.Reader, error)

Resize 调整图片大小(实现 Resizer 接口)

type NativeProcessor

type NativeProcessor struct{}

NativeProcessor implements Resizer using pure Go libraries This avoids CGO dependency (libvips) for easier deployment

func NewNativeProcessor

func NewNativeProcessor() *NativeProcessor

func (*NativeProcessor) GetDimensions

func (p *NativeProcessor) GetDimensions(reader io.Reader) (int, int, error)

func (*NativeProcessor) Resize

func (p *NativeProcessor) Resize(reader io.Reader, width, height uint) (io.Reader, error)

type PipelineImageProcessor

type PipelineImageProcessor interface {
	Process(ctx interface{}, input []byte) ([]byte, error)
	ProcessFromFile(ctx interface{}, filePath string) ([]byte, error)
}

PipelineImageProcessor defines the interface for pipeline-based image processing

type ProcessingPipeline

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

ProcessingPipeline 处理管道

func NewProcessingPipeline

func NewProcessingPipeline(config ImageConfig) *ProcessingPipeline

NewProcessingPipeline 创建处理管道

func (*ProcessingPipeline) Process

func (p *ProcessingPipeline) Process(ctx context.Context, input []byte) ([]byte, error)

Process 处理图片

type ProcessingStep

type ProcessingStep interface {
	Process(ctx context.Context, image []byte) ([]byte, error)
}

ProcessingStep 处理步骤接口

type ResizeOptions

type ResizeOptions struct {
	Width   uint
	Height  uint
	Quality int
	Format  string
}

ResizeOptions defines options for image resizing

type ResizeStep

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

ResizeStep 调整大小步骤

func (ResizeStep) Process

func (s ResizeStep) Process(ctx context.Context, data []byte) ([]byte, error)

ResizeStep 实现

type Resizer

type Resizer interface {
	// Resize creates a thumbnail with specified dimensions
	Resize(reader io.Reader, width, height uint) (io.Reader, error)
	// GetDimensions returns image width and height
	GetDimensions(reader io.Reader) (int, int, error)
}

Resizer defines interface for simple image resizing

type ValidateStep

type ValidateStep struct{}

ValidateStep 验证步骤

func (ValidateStep) Process

func (s ValidateStep) Process(ctx context.Context, data []byte) ([]byte, error)

ValidateStep 实现

type WatermarkStep

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

WatermarkStep 水印步骤

func (WatermarkStep) Process

func (s WatermarkStep) Process(ctx context.Context, data []byte) ([]byte, error)

WatermarkStep 实现

Jump to

Keyboard shortcuts

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