compress

package module
v0.0.0-...-0435f0b Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2024 License: MIT Imports: 5 Imported by: 0

README

compress

Compress the image to the specified size using a dichotomy

how to use?

go get github.com/pzxy/compress

examples

b, err := os.ReadFile("img.jpg")
if err != nil {
    t.Fatal(err)
}
b, err = compress.CompressImage(b, 0, 100, 200, 10)
if err != nil {
    t.Fatal(err)
}
_ = os.WriteFile("img2.jpg", b, 0644)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompressImage

func CompressImage(content []byte, minWidth uint, minKB uint, maxKB uint, n int) ([]byte, error)

CompressImage With the minimum width minWidth as the primary constraint, the file size may exceed maxKB. Secondly, within n iterations, perform a binary search for files sized between minKB and maxKB. If not found, return an error; If found, return the file content; if found but the current image width is less than minWidth, use minWidth as the standard.

Types

This section is empty.

Jump to

Keyboard shortcuts

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