-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from samvera/add-thumbnail-property
Add thumbnail property
- Loading branch information
Showing
14 changed files
with
486 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
module IIIFManifest | ||
class DisplayImage | ||
attr_reader :url, :width, :height, :iiif_endpoint, :format | ||
def initialize(url, width:, height:, format: nil, iiif_endpoint: nil) | ||
attr_reader :url, :type, :width, :height, :iiif_endpoint, :format, :thumbnail | ||
def initialize(url, width:, height:, format: nil, iiif_endpoint: nil, thumbnail: nil) | ||
@url = url | ||
@type = 'Image' | ||
@width = width | ||
@height = height | ||
@format = format | ||
@iiif_endpoint = iiif_endpoint | ||
@thumbnail = thumbnail | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
lib/iiif_manifest/v3/manifest_builder/thumbnail_builder.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
module IIIFManifest | ||
module V3 | ||
class ManifestBuilder | ||
class ThumbnailBuilder | ||
attr_reader :display_content, :iiif_thumbnail_factory, :image_service_builder_factory | ||
def initialize(display_content, iiif_thumbnail_factory:, image_service_builder_factory:) | ||
@display_content = display_content | ||
@iiif_thumbnail_factory = iiif_thumbnail_factory | ||
@image_service_builder_factory = image_service_builder_factory | ||
end | ||
|
||
# @return [Array<Object>] | ||
def build | ||
return Array(display_content.thumbnail.map(&:stringify_keys)) unless display_content.thumbnail.nil? | ||
return nil if display_content.type != "Image" || iiif_endpoint.nil? | ||
|
||
build_thumbnail | ||
image_service_builder.apply(thumbnail) | ||
[thumbnail] | ||
end | ||
|
||
private | ||
|
||
def build_thumbnail | ||
thumbnail['id'] = File.join( | ||
display_content.iiif_endpoint.url, | ||
'full', | ||
"!#{max_edge},#{max_edge}", | ||
'0', | ||
'default.jpg' | ||
) | ||
thumbnail['type'] = display_content.type | ||
thumbnail['height'] = (display_content.height * reduction_ratio).round | ||
thumbnail['width'] = (display_content.width * reduction_ratio).round | ||
thumbnail['format'] = display_content.format | ||
end | ||
|
||
def reduction_ratio | ||
width = display_content.width | ||
height = display_content.height | ||
max_edge = @max_edge.to_f | ||
return 1 if width <= max_edge && height <= max_edge | ||
|
||
long_edge = [height, width].max | ||
max_edge / long_edge | ||
end | ||
|
||
def max_edge | ||
@max_edge = ::IIIFManifest.config.max_edge_for_thumbnail | ||
end | ||
|
||
def thumbnail | ||
@thumbnail ||= iiif_thumbnail_factory.new | ||
end | ||
|
||
def iiif_endpoint | ||
display_content.try(:iiif_endpoint) | ||
end | ||
|
||
def image_service_builder | ||
image_service_builder_factory.new(iiif_endpoint) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.