imageutil

package
v0.0.0-...-e74ad27 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SupportedImageExts = map[string]string{
	".png":  "image/png",
	".jpg":  "image/jpeg",
	".jpeg": "image/jpeg",
	".gif":  "image/gif",
	".webp": "image/webp",
}

SupportedImageExts maps file extensions to MIME types.

Functions

func CompressImage

func CompressImage(raw []byte, originalMediaType string) ([]byte, string)

CompressImage attempts to reduce image size by re-encoding as JPEG at progressively lower quality. Returns the (possibly compressed) bytes and the resulting media type. Falls back to original bytes if compression fails.

func HumanFileSize

func HumanFileSize(n int) string

HumanFileSize returns a human-readable size string.

func IsImageFile

func IsImageFile(path string) bool

IsImageFile returns true if path has a supported image extension.

func ReadImageFile

func ReadImageFile(path string) (data string, mediaType string, err error)

ReadImageFile reads an image from disk and returns its base64 data and MIME type. Images larger than imageTargetBytes are compressed before encoding.

Types

This section is empty.

Jump to

Keyboard shortcuts

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