imaging

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package imaging validates uploaded image files with the framework's bounded container inspection. Import it as imagingvalidation alongside the imaging package. Pixels are never decoded. Kind rules correlate captured metadata with the inspected format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dimensions

func Dimensions[F File](limits imaging.Limits, constraints validation.DimensionConstraints) validation.Rule[F]

Dimensions checks an uploaded image's displayed pixel size. Put FileMaxSize and FileContentTypes before it in Bail so cheap metadata rejects first.

func DimensionsWithEngine

func DimensionsWithEngine[F File](engine *imaging.Engine, constraints validation.DimensionConstraints) validation.Rule[F]

DimensionsWithEngine validates uploads using the configured backend, including native formats when available. It borrows the engine without closing it.

func Kinds added in v0.8.0

func Kinds[F File](limits imaging.Limits, constraints validation.DimensionConstraints, allowed ...Kind) validation.Rule[F]

Kinds validates correlated file kinds and dimensions with one bounded portable inspection. Zero constraints omit application dimension checks; engine byte, pixel and other resource limits remain enforced. Wrap this leaf in WithTranslation to retain an application's image message.

func KindsWithEngine added in v0.8.0

func KindsWithEngine[F File](engine *imaging.Engine, constraints validation.DimensionConstraints, allowed ...Kind) validation.Rule[F]

KindsWithEngine borrows the configured engine for a single kind and dimension inspection, including native formats when available. The caller owns its lifetime.

Types

type File

type File interface {
	validation.FileValue
	// Open opens a seekable file reader that the caller must close.
	Open(context.Context) (io.ReadSeekCloser, error)
}

File is captured upload metadata with a bounded reopenable reader. HTTP UploadedFile implements it.

type Kind added in v0.8.0

Kind correlates an extension, optional detected MIME type, and engine format. Empty ContentType means engine inspection alone establishes the content kind.

func AVIFKind added in v0.8.0

func AVIFKind() Kind

AVIFKind declares avif using container inspection, without requiring the bounded upload MIME sniff to recognize AVIF.

func GIFKind added in v0.8.0

func GIFKind() Kind

GIFKind declares gif with GIF content.

func JPEGKind added in v0.8.0

func JPEGKind() Kind

JPEGKind declares jpg with JPEG content. Set Extension to jpeg to allow that alias.

func PNGKind added in v0.8.0

func PNGKind() Kind

PNGKind declares png with PNG content.

func WebPKind added in v0.8.0

func WebPKind() Kind

WebPKind declares webp with WebP content.

type Measurer

type Measurer[F File] struct {
	// contains filtered or unexported fields
}

Measurer reads a captured file of at most Limits.InputBytes into memory and inspects its container with the portable inspector or a borrowed Engine. Larger, absent, unsupported or malformed files reject; read and open failures are execution failures. EXIF-style orientations that rotate by 90 degrees swap width and height, so constraints apply to the displayed image.

func NewEngineMeasurer

func NewEngineMeasurer[F File](engine *imaging.Engine) Measurer[F]

NewEngineMeasurer uses an existing engine's backend, bounds and admission. The application retains ownership of the engine and must keep it open.

func NewMeasurer

func NewMeasurer[F File](limits imaging.Limits) Measurer[F]

NewMeasurer creates an image measurer with the supplied inspection limits.

func (Measurer[F]) Inspect added in v0.8.0

func (m Measurer[F]) Inspect(ctx context.Context, file F) (validation.ImageInspection[imaging.Format], bool, error)

Inspect reads once and returns the container format and displayed dimensions. It retains Measure's bounds and rejection/execution-error distinction.

func (Measurer[F]) Measure

func (m Measurer[F]) Measure(ctx context.Context, file F) (validation.ImageSize, bool, error)

Measure reads and inspects bounded file content, correcting dimensions for orientation. Absent, unsupported, or invalid images return false without an error.

func (Measurer[F]) Validate

func (m Measurer[F]) Validate() error

Validate validates the configured engine or standalone inspection limits.

Jump to

Keyboard shortcuts

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