Skip to content

Commit

Permalink
adjustments for collections#show image size/layout
Browse files Browse the repository at this point in the history
  • Loading branch information
ebenenglish committed Jan 8, 2021
1 parent 3e9181d commit 3322b44
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

h1.collection-title {
line-height: 32px;
margin-bottom: 20px;
margin-bottom: 10px;
}

h4.collection-provenance {
Expand All @@ -73,7 +73,7 @@ h4.collection-provenance {
#collection_img {
float: left;
width: 33%;
margin: 0 23px 24px 0;
margin: 0 23px 20px 0;

img.collection_img_show {
border: 1px solid $light_gray;
Expand Down
25 changes: 13 additions & 12 deletions app/helpers/commonwealth_vlr_engine/collections_helper_behavior.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,22 @@ def render_collection_image(image_tag_class = nil)
end

# the IIIF URL for the image to be displayed on collections#show
# preferred dimensions: 1100 width, 400 height
# if the image is too wide or narrow, return a square
def collection_image_url(image_pid, target_width = 1100, target_height = 400)
# preferred dimensions: 1100 width, 450 height
def collection_image_url(image_pid, target_width = 1100, target_height = 450)
image_info = get_image_metadata(image_pid)
aspect = image_info[:aspect_ratio]
if aspect > 1.67 || aspect < 0.33
region = 'square'
if image_info[:aspect_ratio] > 2.2
top = 0
height = image_info[:height]
output_aspect = target_width.to_f / target_height.to_f
width = (height * output_aspect).round
else
scale_height = (target_width / aspect).round
width_percent = (target_width.to_f / image_info[:width].to_f).round(3)
excess_scaled = (scale_height - target_height) / 2
excess_orig = (excess_scaled / width_percent).round
orig_slice_height = (target_height / width_percent).round
region = "0,#{excess_orig},#{image_info[:width]},#{orig_slice_height}"
width = (image_info[:width].to_f * 0.90).round # 90% so we don't get borders
reduction_percent = (target_width.to_f / width.to_f).round(3)
height = (target_height / reduction_percent).round
top = (image_info[:height] - height) / 2
end
left = (image_info[:width] - width) / 2
region = "#{left},#{top},#{width},#{height}"
iiif_image_url(image_pid, { region: region, size: "#{target_width}," })
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
</dd>
<% end %>
<%# additional rights/use info field %>
<% if document[:restrictions_on_access_ssm].present? %>
<% if document[:restrictions_on_access_ssm]&.first.present? %>
<dt class="col-md-3"><%= t('blacklight.metadata_display.fields.access') %>:</dt>
<dd class="col-md-9">
<% document[:restrictions_on_access_ssm].each do |restrictions| %>
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/collections_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
describe '#collection_image_url' do
it 'returns the correct url' do
col_img_url = helper.collection_image_url(image_pid)
expect(col_img_url).to eq("#{IIIF_SERVER['url']}#{image_pid}/0,952,1496,544/1100,/0/default.jpg")
expect(col_img_url).to eq("#{IIIF_SERVER['url']}#{image_pid}/75,948,1346,551/1100,/0/default.jpg")
end
end

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3322b44

Please sign in to comment.