cp

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

README

gocp

例子


import cp "github.com/cytzrs/gocp"

imgPath := "lion.jpg"
buf, err := Compress(p, &ImageCompressor{
				Format:  "jpg",
				Quality: 75,
				Resize:  true,
				Height:  4096,
				Width:   3072,
			})
if err != nil {
    fmt.Println("compressed_failed:" + err.Error())
    return
}

if buf == nil {
    fmt.Println("=====================buf_failed=====================")
    return
}

if err := os.WriteFile(outPath, buf, 0644); err != nil {
    fmt.Println("write_failed:" + err.Error())
    return
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compress

func Compress(imgPath string, params *ImageCompressor) ([]byte, error)

func Optimize

func Optimize(src gocv.Mat) (gocv.Mat, error)

Types

type ImageCompressor added in v0.0.3

type ImageCompressor struct {
	Quality int
	Format  string
	Resize  bool
	Height  int
	Width   int
}

func NewImageCompressor added in v0.0.3

func NewImageCompressor(opts ...Option) *ImageCompressor

type Option added in v0.0.3

type Option func(*ImageCompressor)

func WithFormat added in v0.0.3

func WithFormat(format string) Option

func WithQuality added in v0.0.3

func WithQuality(quality int) Option

func WithResize added in v0.0.3

func WithResize(resize bool, width, height int) Option

Jump to

Keyboard shortcuts

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