Documentation
¶
Index ¶
- func DecodeAny(r io.Reader) (image.Image, string, error)
- func DownloadAndDecodeAny(ctx context.Context, url string) (image.Image, string, error)
- func DownloadAndDecodeAnyWithLimit(ctx context.Context, url string, maxBytes int64) (image.Image, string, error)
- func DownscaleByLargestSide(src image.Image, maxSide uint32) image.Image
- func Grayscale(src image.Image) *image.Gray
- func HammingDistance(a, b uint64) int
- func PHash(image image.Image) uint64
- func Resize(src image.Image, dstW, dstH uint32) image.Image
- type DecodeError
- type DecodeOp
- type EncodeError
- type EncodeOp
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeAny ¶
DecodeAny reads all bytes (so it works with non-seekable readers), decodes, and applies EXIF orientation. It returns the decoded image and the detected format string ("jpeg", "png", "gif", "webp", ...). Errors are returned as DecodeError with Op "read" or "decode".
func DownloadAndDecodeAny ¶
DownloadAndDecodeAny fetches a remote image over HTTP, decodes it, and applies EXIF orientation. Errors are returned as DecodeError with Op "request", "http", "http status", or "decode".
func DownloadAndDecodeAnyWithLimit ¶
func DownloadAndDecodeAnyWithLimit(ctx context.Context, url string, maxBytes int64) (image.Image, string, error)
DownloadAndDecodeAnyWithLimit fetches a remote image over HTTP, decodes it with a byte cap, and applies EXIF orientation. Errors are returned as DecodeError with Op "request", "http", "http status", or "decode".
func DownscaleByLargestSide ¶
DownscaleByLargestSide scales the image down so the largest side is at most maxSide, preserving aspect ratio. If no downscale is needed, it returns src. If src is nil or maxSide is 0, it returns src.
func Grayscale ¶
Grayscale converts any image.Image to *image.Gray. Uses standard luminance conversion (sRGB).
func HammingDistance ¶
HammingDistance returns the number of differing bits between two 64-bit hashes.
func PHash ¶
PHash computes a classic 64-bit perceptual hash (pHash).
Pipeline (classic 64-bit):
- Resize to 32x32
- Grayscale
- 2D DCT (N=32), keep top-left 8x8 coefficients
- Median of 63 coefficients excluding DC
- Build 64-bit hash: bit=1 if coeff>median, with DC bit forced to 0
func Resize ¶
ResizeMultiStep resizes src to (dstW, dstH) using a quality-preserving strategy.
- If dstW==0 or dstH==0, aspect ratio is preserved. - Downscale: progressive halving using CatmullRom, then final CatmullRom to exact size. - Upscale: single ApproxBiLinear pass (smoother, fewer halos).
Official repos only: stdlib + golang.org/x/image/draw.
Types ¶
type DecodeError ¶
func (DecodeError) Error ¶
func (e DecodeError) Error() string
Error formats DecodeError as "op: err" (or "op" when Err is nil).
type DecodeOp ¶
type DecodeOp string
DecodeError describes failures in HTTP setup, HTTP status, IO reads, or image decoding. Returned by the helpers in decode.go to avoid raw fmt.Errorf strings.
type EncodeError ¶
func (EncodeError) Error ¶
func (e EncodeError) Error() string
Error formats EncodeError as "op: err" (or "op" when Err is nil).