analyzer

package
v0.0.0-...-eeb11c7 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: BSD-3-Clause Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DimensionProbeInitialBytes is the number of leading bytes read on the
	// first dimension-probing attempt. Image headers are almost always within
	// this prefix, so a single ranged read usually suffices — including for
	// JPEGs carrying large EXIF thumbnails.
	DimensionProbeInitialBytes int64 = 64 * 1024

	// DimensionProbeMaxBytes caps how much of an image may be read while
	// probing its dimensions. Images whose headers exceed this budget are
	// skipped rather than fully read.
	DimensionProbeMaxBytes int64 = 1024 * 1024
)

Variables

This section is empty.

Functions

func InspectImage

func InspectImage(system fs.FS, link manifest.Link, algorithms []manifest.HashAlgorithm) (*manifest.Link, error)

InspectImage inspects an image located in the provided filesystem, using the provided link's manifest.HREF as a path. Additional properties from the link, such as the mediatype.MediaType, may be used, and should be included. A copy of the provided link will be returned, with the `size`, `width`, `height` and `properties.animated` attributes set. A slice of manifest.HashAlgorithm can be provided, in which case the returned link will also have `properties.hash` set with the computed hashes. Currently, the supported algorithms are: manifest.HashAlgorithmSHA256, manifest.HashAlgorithmMD5, manifest.HashAlgorithmPhashDCT, and `https://blurha.sh` (BlurHash). The latter two are visual hashes, which are more computationally expensive.

func MatchImage

func MatchImage(link manifest.Link, hashes manifest.HashList) (bool, error)

MatchImage compares the link with the given hashes to determine if they match.

func ProbeImageDimensions

func ProbeImageDimensions(read LeadingByteReader) (width uint, height uint, err error)

ProbeImageDimensions determines an image's pixel dimensions from as few leading bytes as possible, without decoding any pixel data. When the first read is truncated mid-header, the reader is retried with a larger budget up to DimensionProbeMaxBytes.

Formats handled: everything registered with the standard image package (GIF, JPEG, PNG) plus WebP, which is probed explicitly. AVIF and JXL are not supported and return an error, mirroring InspectImage.

func ProbeImageDimensionsInFS

func ProbeImageDimensionsInFS(fsys fs.FS, path string) (uint, uint, error)

ProbeImageDimensionsInFS probes the dimensions of the bitmap at path within fsys.

Types

type LeadingByteReader

type LeadingByteReader func(n int64) ([]byte, error)

LeadingByteReader returns up to n leading bytes of an image. It may return fewer bytes than requested when the source is shorter; it must be safe to call repeatedly (each call restarts from the beginning of the image).

Jump to

Keyboard shortcuts

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