iiif

package
v2.10.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2018 License: CC0-1.0 Imports: 6 Imported by: 0

Documentation

Overview

Package iiif defines various parsing options and compliance-level information for dealing with a web request for an IIIF resource/operation

Index

Constants

This section is empty.

Variables

Formats is the definitive list of all possible Format constants

Qualities is the definitive list of all possible Quality constants

Functions

This section is empty.

Types

type FeatureSet

type FeatureSet struct {
	// Region options: note that full isn't specified but must be supported
	RegionByPx  bool
	RegionByPct bool

	// Size options: note that full isn't specified but must be supported
	SizeByWhListed bool
	SizeByW        bool
	SizeByH        bool
	SizeByPct      bool
	SizeByForcedWh bool
	SizeByWh       bool
	SizeAboveFull  bool

	// Rotation and mirroring
	RotationBy90s     bool
	RotationArbitrary bool
	Mirroring         bool

	// "Quality" (color model / color depth)
	Default bool
	Color   bool
	Gray    bool
	Bitonal bool

	// Format
	Jpg  bool
	Png  bool
	Tif  bool
	Gif  bool
	Jp2  bool
	Pdf  bool
	Webp bool

	// HTTP features
	BaseURIRedirect     bool
	Cors                bool
	JsonldMediaType     bool
	ProfileLinkHeader   bool
	CanonicalLinkHeader bool

	// Non-boolean feature support
	TileSizes []TileSize
}

FeatureSet represents possible IIIF 2.0 features. The boolean fields are the same as the string to report features, except that the first character should be lowercased.

Note that using this in a different server only gets you so far. As noted in the Supported() documentation below, verifying complete support is trickier than just checking a URL, and a server that doesn't support arbitrary resizing can still advertise specific sizes that will work.

func FeatureSet0

func FeatureSet0() *FeatureSet

FeatureSet0 returns a copy of the feature set required for a level-0-compliant IIIF server

func FeatureSet1

func FeatureSet1() *FeatureSet

FeatureSet1 returns a copy of the feature set required for a level-1-compliant IIIF server

func FeatureSet2

func FeatureSet2() *FeatureSet

FeatureSet2 returns a copy of the feature set required for a level-2-compliant IIIF server

func (*FeatureSet) Info

func (fs *FeatureSet) Info() *Info

Info returns the default structure for a FeatureSet's info response JSON. The caller is responsible for filling in image-specific values (ID and dimensions).

func (*FeatureSet) Profile

func (fs *FeatureSet) Profile() []InfoProfile

Profile examines the features in the FeatureSet to determine first which level the FeatureSet supports, then adds any variances.

func (*FeatureSet) Supported

func (fs *FeatureSet) Supported(u *URL) bool

Supported tells us whether or not the given feature set will actually perform the operation represented by the URL instance.

Unsupported functionality is expected to report an http status of 501.

This doesn't actually work in all cases, such as a level 0 server that has sizes explicitly listed for a given image resize operation. In those cases, Supported() is probably not worth calling, instead handling just the few supported cases directly and/or checking a custom featureset directly.

This also doesn't actually check all possibly supported features - the URL type is useful for parsing a URI path, but doesn't know about e.g. http features.

func (*FeatureSet) SupportsFormat

func (fs *FeatureSet) SupportsFormat(f Format) bool

SupportsFormat just verifies a given format type is supported

func (*FeatureSet) SupportsQuality

func (fs *FeatureSet) SupportsQuality(q Quality) bool

SupportsQuality just verifies a given quality type is supported

func (*FeatureSet) SupportsRegion

func (fs *FeatureSet) SupportsRegion(r Region) bool

SupportsRegion just verifies a given region type is supported

func (*FeatureSet) SupportsRotation

func (fs *FeatureSet) SupportsRotation(r Rotation) bool

SupportsRotation just verifies a given rotation type is supported

func (*FeatureSet) SupportsSize

func (fs *FeatureSet) SupportsSize(s Size) bool

SupportsSize just verifies a given size type is supported

type FeaturesMap

type FeaturesMap map[string]bool

FeaturesMap is a simple map for boolean features, used for comparing featuresets and reporting features beyond the reported level

func FeatureCompare

func FeatureCompare(a, b *FeatureSet) (union, onlyA, onlyB FeaturesMap)

FeatureCompare returns which features are in common between two FeatureSets, which are exclusive to a, and which are exclusive to b. The returned maps will ONLY contain keys with a value of true, as opposed to the full list of features and true/false. This helps to quickly determine equality, subset status, and superset status.

type Format

type Format string

Format represents an IIIF 2.0 file format a client may request

const (
	FmtJPG  Format = "jpg"
	FmtTIF  Format = "tif"
	FmtPNG  Format = "png"
	FmtGIF  Format = "gif"
	FmtJP2  Format = "jp2"
	FmtPDF  Format = "pdf"
	FmtWEBP Format = "webp"
)

All known file formats for IIIF 2.0

func (Format) Valid

func (f Format) Valid() bool

Valid returns whether a given Format string is valid. Since a Format can be created via Format("blah"), this ensures the format is, in fact, within the list of known formats.

type ID

type ID string

ID is a string identifying a particular file to process. It can contain URI-encoded data in order to allow, e.g., full paths.

func (ID) Path

func (id ID) Path() string

Path unescapes "percentage encoding" to return a more friendly value for path-on-disk usage.

func (ID) String

func (id ID) String() string

String just gives the ID as it was created, but obviously as a string type

type Info

type Info struct {
	Context  string        `json:"@context"`
	ID       string        `json:"@id"`
	Protocol string        `json:"protocol"`
	Width    int           `json:"width"`
	Height   int           `json:"height"`
	Tiles    []TileSize    `json:"tiles,omitempty"`
	Profile  []InfoProfile `json:"profile"`
}

Info represents the simplest possible data to provide a valid IIIF information JSON response

func NewInfo

func NewInfo() *Info

NewInfo returns the static *Info data that's the same for any info response

type InfoProfile

type InfoProfile interface{}

InfoProfile is an empty interface strictly for serializing JSON since we need an array that has strings as well as sub-structures

type Quality

type Quality string

Quality is the representation of an IIIF 2.0 quality (color space / depth) which a client may request. We also include "native" for better compatibility with older clients, since it's the same as "default".

const (
	QColor   Quality = "color"
	QGray    Quality = "gray"
	QBitonal Quality = "bitonal"
	QDefault Quality = "default"
	QNative  Quality = "native" // For 1.1 compatibility
)

All possible qualities for IIIF 2.0 and 1.1

func (Quality) Valid

func (q Quality) Valid() bool

Valid returns whether a given Quality string is valid. Since a Quality can be created via Quality("blah"), this ensures the quality is, in fact, within the list of known qualities.

type Region

type Region struct {
	Type       RegionType
	X, Y, W, H float64
}

Region represents the part of the image we'll manipulate. It can be thought of as the cropping rectangle.

func StringToRegion

func StringToRegion(p string) Region

StringToRegion takes a string representing a region, as seen in an IIIF URL, and fills in the values based on the string's format.

func (Region) Valid

func (r Region) Valid() bool

Valid checks for (a) a known region type, and then (b) verifies that the values are valid for the given type. There is no attempt to check for per-image correctness, just general validity.

type RegionType

type RegionType int

A RegionType tells us what a Region is representing so we know how to apply the x/y/w/h values

const (
	// RTNone means we didn't find a valid region string
	RTNone RegionType = iota
	// RTFull means we ignore x/y/w/h and use the whole image
	RTFull
	// RTPercent means we interpret x/y/w/h as percentages of the image size
	RTPercent
	// RTPixel means we interpret x/y/w/h as precise coordinates within the image
	RTPixel
)

type Rotation

type Rotation struct {
	Mirror  bool
	Degrees float64
}

Rotation represents the degrees of rotation and whether or not an image is mirrored, as both are defined in IIIF 2.0 as being part of the rotation parameter in IIIF URL requests.

func StringToRotation

func StringToRotation(p string) Rotation

StringToRotation creates a Rotation from a string as seen in an IIIF URL. An invalid string would result in a 0-degree rotation as opposed to an error condition. This is a known issue which needs to be fixed.

func (Rotation) Valid

func (r Rotation) Valid() bool

Valid just returns whether or not the degrees value is within a sane range: 0 <= r.Degrees < 360

type Size

type Size struct {
	Type    SizeType
	Percent float64
	W, H    int
}

Size represents the type of scaling as well as the parameters for scaling for an IIIF 2.0 server

func StringToSize

func StringToSize(p string) Size

StringToSize creates a Size from a string as seen in an IIIF URL.

func (Size) Valid

func (s Size) Valid() bool

Valid returns whether the size has a valid type, and if so, whether the parameters are valid for that type

type SizeType

type SizeType int

SizeType represents the type of scaling which will be performed

const (
	// STNone is used when the Size struct wasn't able to be parsed form a string
	STNone SizeType = iota
	// STFull means no scaling is requested
	STFull
	// STScaleToWidth requests the image be scaled to a set width (aspect ratio
	// is preserved)
	STScaleToWidth
	// STScaleToHeight requests the image be scaled to a set height (aspect ratio
	// is preserved)
	STScaleToHeight
	// STScalePercent requests the image be scaled by a set percent of its size
	// (aspect ratio is preserved)
	STScalePercent
	// STExact requests the image be resized to precise width and height
	// dimensions (aspect ratio is not preserved)
	STExact
	// STBestFit requests the image be resized *near* the given width and height
	// dimensions (aspect ratio is preserved)
	STBestFit
)

type TileSize

type TileSize struct {
	Width        int   `json:"width"`
	Height       int   `json:"height,omitempty"`
	ScaleFactors []int `json:"scaleFactors"`
}

TileSize represents a supported tile size for a feature set to expose. This data is serialized in an info request and therefore must have JSON tags.

type URL

type URL struct {
	Path     string
	ID       ID
	Region   Region
	Size     Size
	Rotation Rotation
	Quality  Quality
	Format   Format
}

URL represents the different options composed into an IIIF URL request

func NewURL

func NewURL(path string) *URL

NewURL takes a path string (no scheme, server, or prefix, just the IIIF pieces), such as "somefile.jp2/full/512,/270/default.jpg", and breaks it down into the different components. In this example:

  • ID: "somefile.jp2" (the server determines how to find this)
  • Region: "full" (the whole image is processed)
  • Size: "512," (the image is resized to a width of 512; aspect ratio is maintained)
  • Rotation: "270" (the image is rotated 270 degrees clockwise)
  • Quality: "default" (the image color space is unchanged)
  • Format: "jpg" (the resulting image will be a JPEG)

func (*URL) Valid

func (u *URL) Valid() bool

Valid returns the validity of the request - is the syntax is bad in any way? Are any numbers outside a set range? Was the identifier blank? Etc.

Invalid requests are expected to report an http status of 400.

Jump to

Keyboard shortcuts

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