Documentation
¶
Index ¶
- Constants
- func InspectImage(system fs.FS, link manifest.Link, algorithms []manifest.HashAlgorithm) (*manifest.Link, error)
- func MatchImage(link manifest.Link, hashes manifest.HashList) (bool, error)
- func ProbeImageDimensions(read LeadingByteReader) (width uint, height uint, err error)
- func ProbeImageDimensionsInFS(fsys fs.FS, path string) (uint, uint, error)
- type LeadingByteReader
Constants ¶
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 ¶
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.
Types ¶
type LeadingByteReader ¶
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).