v0.0.0-...-064f8e4 Latest Latest

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

Go to latest
Published: Feb 12, 2024 License: MIT Imports: 9 Imported by: 0



imagerequest offers functions to parse, validate, and resolve image parameters into more usable forms.



This section is empty.


This section is empty.


This section is empty.


type ParsedParams

type ParsedParams struct {
	RegionIsEnum    bool
	RegionEnum      string
	RegionIsPercent bool
	RegionPercent   [4]float32
	RegionPixels    [4]uint32

	SizeIsConfined bool
	SizeIsUpscaled bool
	SizeIsEnum     bool
	SizeEnum       string
	SizeIsPercent  bool
	SizePercent    float32
	SizePixels     [2]*uint32

	RotationIsMirrored bool
	RotationAmount     float32

	Quality string

	Format string

ParsedParams represents the destructured values of the image request params. This is typically constructed through the ParseRawParams function.

func NewParsedParamsFromPixelset

func NewParsedParamsFromPixelset(regionSize pixelset.Value, quality, format string) ParsedParams

func ParseRawParams

func ParseRawParams(segments RawParams) (ParsedParams, error)

ParseRawParams parses RawParams values and performs syntactic validation of the values. The result represents specification-valid parameters, however it may not be valid for an individual image. The ParsedParams.Resolve function should be used to ensure it is fully valid.

func (ParsedParams) Clone

func (p ParsedParams) Clone() ParsedParams

func (ParsedParams) FileString

func (p ParsedParams) FileString() string

func (ParsedParams) RegionString

func (p ParsedParams) RegionString() string

func (ParsedParams) Resolve

func (p ParsedParams) Resolve(opts ResolveOptions) (ResolvedParams, error)

Resolve validates all properties to ensure they are supported by the given iiifimageapi.ImageInformation and converts any relative values to absolute pixel values. The result should be usable by an image processor with no additional calculations.

func (ParsedParams) RotationString

func (p ParsedParams) RotationString() string

func (ParsedParams) SizeString

func (p ParsedParams) SizeString() string

func (ParsedParams) String

func (p ParsedParams) String() string

type RawParams

type RawParams [4]string

RawParams represents the raw [{region}, {size}, {rotation}, {quality.format}] values described in the specification.

func RawParamsFromString

func RawParamsFromString(raw string) (RawParams, error)

RawParamsFromString decodes path segments from a `{region}/{size}/{rotation}/{quality}.{format}` string.

func (RawParams) String

func (p RawParams) String() string

type ResolveOptions

type ResolveOptions struct {
	// ImageInformation must be configured with, at a minimum, the profile, width, and height fields.
	ImageInformation iiifimageapi.ImageInformation

	// DefaultQuality must be a valid quality which will be used when the input is "default".
	DefaultQuality string

	// ComplianceLevels may be a set to supported levels to use. If nil, [iiifimageapi.DefaultComplianceLevels] will be used.
	ComplianceLevels iiifimageapi.ComplianceLevels

	// IgnoreFeatureErrors may be set to true to ignore would-be errors due to unsupported features (according to
	// ImageInformation). Typically this should only be used when a caller is acting in an administrative role.
	IgnoreFeatureErrors bool

	// IgnoreFeatureErrors may be set to true to ignore max width/height/area constraints (according to ImageInformation).
	// Typically this should only be used when a caller is acting in an administrative role.
	IgnoreMaxConstraints bool

ResolverOptions contains the properties which affect how parameters are interpreted.

type ResolvedParams

type ResolvedParams struct {
	// contains filtered or unexported fields

ResolvedParams is the result of ParsedParams.Resolve for a particular [spec.ImageInformation]. It contains absolute pixel dimensions and is the minimal set of information required by an image processor.

func (ResolvedParams) Canonical

func (p ResolvedParams) Canonical() ParsedParams

Canonical returns the expanded form according to the original resolver options.

func (ResolvedParams) Format

func (p ResolvedParams) Format() string

Format is the requested format (e.g. "jpg").

func (ResolvedParams) Quality

func (p ResolvedParams) Quality() string

Quality is the literal quality to render (not "default").

func (ResolvedParams) RegionPixels

func (p ResolvedParams) RegionPixels() [4]uint32

RegionPixels returns the pixel set of [X, Y, Width, Height].

func (ResolvedParams) ResolveCanonical

func (p ResolvedParams) ResolveCanonical(opts ResolveOptions) ParsedParams

ResolveCanonical returns the expanded form according to the given opts.

func (ResolvedParams) RotationAmount

func (p ResolvedParams) RotationAmount() float32

RotationAmount returns the amount an image should be rotated from 0 (inclusive) to 360 (exclusive).

func (ResolvedParams) RotationIsMirrored

func (p ResolvedParams) RotationIsMirrored() bool

RotationIsMirrored returns true if it should be mirrored acorss the vertical axis before rotation.

func (ResolvedParams) SizePixels

func (p ResolvedParams) SizePixels() [2]uint32

SizePixels returns the pixel set of [Width, Height].

func (ResolvedParams) ToParsedParams

func (p ResolvedParams) ToParsedParams() ParsedParams

ToParsedParams returns the parameters in expanded form.

Jump to

Keyboard shortcuts

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