utils

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoCompression      clv = 0 // No compression
	BestSpeed          clv = 1 // Best speed
	DefaultCompression clv = 2 // Default compression
	BestCompression    clv = 3 // Best compression
)

Variables

This section is empty.

Functions

func CompareImgFormFolders

func CompareImgFormFolders(inputDir, outputDir string) []string

func DecImg

func DecImg(r io.Reader) (image.Image, error)

DecImg Supported formats:

  • JPEG
  • PNG
  • TIFF
  • BMP
  • WEBP

func EncImg

func EncImg(w io.Writer, img image.Image, format ImageFormat, compressionLevel ...SetClv) error

EncImg encodes the image to the specified format and writes it to the writer. Parameters:

  • w: the writer to write the encoded image
  • img: the image to encode
  • format: the image format to encode
  • compressionLevel: the compression level to use, default is NoCompression

Returns:

  • error: an error if the format is unsupported or if encoding fails

Supported formats:

  • JPEG
  • PNG
  • TIFF
  • BMP
  • WEBP

func GetLastFolderName

func GetLastFolderName(path string) string

GetLastFolderName

Parameters:

  • path: the path

Returns:

  • string: the last folder name

Example:

folderName := GetLastFolderName("./sprites/atlas/a.png")
// folderName = "atlas"

func GetOpaqueBounds

func GetOpaqueBounds(img image.Image, tolerance uint8) image.Rectangle

GetOpaqueBounds returns the bounds of the opaque area of the image. The image is assumed to be in RGBA format.

func ListFilePaths

func ListFilePaths(dirPath string) ([]string, error)

ListFilePaths

Parameters:

  • dirPath: the directory path

Returns:

  • []string: the file paths
  • error: the error

Example:

filePaths, err := ListFilePaths("./sprites")

func LoadImg

func LoadImg(pathName string) (image.Image, error)

func MaxInt

func MaxInt(a, b int) int

MaxInt returns the larger of a and b.

func MinInt

func MinInt(a, b int) int

MinInt returns the smaller of a and b.

func NaturalLess

func NaturalLess(a, b string) bool

func NaturalSort

func NaturalSort(items []string)

NaturalSort sorts the items in natural order.

func Parallel

func Parallel(start, stop int, fn func(<-chan int))

func Rotate180

func Rotate180(img image.Image) *image.NRGBA

Rotate180 rotates the image 180 degrees counter-clockwise and returns the transformed image.

func Rotate270

func Rotate270(img image.Image) *image.NRGBA

Rotate270 rotates the image 270 degrees counter-clockwise and returns the transformed image.

func Rotate90

func Rotate90(img image.Image) *image.NRGBA

Rotate90 rotates the image 90 degrees counter-clockwise and returns the transformed image.

func SafeCreate

func SafeCreate(outputPath string) (*os.File, error)

func SaveImgAutoExt

func SaveImgAutoExt(pathNoneExt string, img image.Image, format ImageFormat, compressionLevel ...SetClv) error

func SaveImgByExt

func SaveImgByExt(outputPath string, img image.Image, compressionLevel ...SetClv) error

Types

type ImageFormat

type ImageFormat int
const (
	JPEG ImageFormat = iota
	PNG
	TIFF
	BMP
	WEBP
)

type SameDetectInfo

type SameDetectInfo struct {
	//ccc.png -> aaa.png
	//bbb.png -> aaa.png
	DupeToBaseName map[string]string
	//aaa.png -> [ccc.png, bbb.png]
	BaseToDupesName map[string][]string
}

func FindDuplicateFiles

func FindDuplicateFiles(filePaths []string) ([]string, SameDetectInfo, error)

FindDuplicateFiles finds duplicate files in the given file paths.

Parameters:

  • filePaths: the paths of the files to be checked

Returns:

  • []string: the paths of the unique files
  • map[string]string: the map of duplicate file names and their corresponding base names
  • map[string][]string: the map of base file names to their duplicate file names
  • error

type SetClv

type SetClv func(*encodeImgOpt)

func WithCLV

func WithCLV(clv clv) SetClv

WithCLV sets the compression level for the image.

Jump to

Keyboard shortcuts

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