Documentation ¶
Overview ¶
Package iiif defines various parsing options and compliance-level information for dealing with a web request for an IIIF resource/operation
Index ¶
- Variables
- type FeatureSet
- func (fs *FeatureSet) Info() *Info
- func (fs *FeatureSet) Profile() []InfoProfile
- func (fs *FeatureSet) Supported(u *URL) bool
- func (fs *FeatureSet) SupportsFormat(f Format) bool
- func (fs *FeatureSet) SupportsQuality(q Quality) bool
- func (fs *FeatureSet) SupportsRegion(r Region) bool
- func (fs *FeatureSet) SupportsRotation(r Rotation) bool
- func (fs *FeatureSet) SupportsSize(s Size) bool
- type FeaturesMap
- type Format
- type ID
- type Info
- type InfoProfile
- type Quality
- type Region
- type RegionType
- type Rotation
- type Size
- type SizeType
- type TileSize
- type URL
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 ¶
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
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.
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
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".
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 ¶
StringToRegion takes a string representing a region, as seen in an IIIF URL, and fills in the values based on the string's format.
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 ¶
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 ¶
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.
type Size ¶
Size represents the type of scaling as well as the parameters for scaling for an IIIF 2.0 server
func StringToSize ¶
StringToSize creates a Size from a string as seen in an IIIF URL.
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 ¶
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)