imaging

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 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 and filenames/client MIME are not consulted.

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.

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 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]) 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