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 ¶
- func Dimensions[F File](limits imaging.Limits, constraints validation.DimensionConstraints) validation.Rule[F]
- func DimensionsWithEngine[F File](engine *imaging.Engine, constraints validation.DimensionConstraints) validation.Rule[F]
- func Kinds[F File](limits imaging.Limits, constraints validation.DimensionConstraints, ...) validation.Rule[F]
- func KindsWithEngine[F File](engine *imaging.Engine, constraints validation.DimensionConstraints, ...) validation.Rule[F]
- type File
- type Kind
- type Measurer
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
type Kind = validation.ImageKind[imaging.Format]
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.
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 ¶
NewEngineMeasurer uses an existing engine's backend, bounds and admission. The application retains ownership of the engine and must keep it open.
func NewMeasurer ¶
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.