From 3322b44cb9aec6d47d934e4e28a495ca8a83ad9b Mon Sep 17 00:00:00 2001 From: Eben English Date: Fri, 8 Jan 2021 10:18:05 -0500 Subject: [PATCH] adjustments for collections#show image size/layout --- .../commonwealth-vlr-engine/collections.scss | 4 +-- .../collections_helper_behavior.rb | 25 ++++++++++--------- .../_show_default_metadata.html.erb | 2 +- spec/helpers/collections_helper_spec.rb | 2 +- .../returns_the_correct_url.yml | 6 ++--- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/app/assets/stylesheets/commonwealth-vlr-engine/collections.scss b/app/assets/stylesheets/commonwealth-vlr-engine/collections.scss index 9acdc3f5..ff5f6969 100644 --- a/app/assets/stylesheets/commonwealth-vlr-engine/collections.scss +++ b/app/assets/stylesheets/commonwealth-vlr-engine/collections.scss @@ -50,7 +50,7 @@ h1.collection-title { line-height: 32px; - margin-bottom: 20px; + margin-bottom: 10px; } h4.collection-provenance { @@ -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; diff --git a/app/helpers/commonwealth_vlr_engine/collections_helper_behavior.rb b/app/helpers/commonwealth_vlr_engine/collections_helper_behavior.rb index e56ba379..a2bcc5dd 100644 --- a/app/helpers/commonwealth_vlr_engine/collections_helper_behavior.rb +++ b/app/helpers/commonwealth_vlr_engine/collections_helper_behavior.rb @@ -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 diff --git a/app/views/catalog/_show_partials/_show_default_metadata.html.erb b/app/views/catalog/_show_partials/_show_default_metadata.html.erb index a465a284..ae0e45cf 100644 --- a/app/views/catalog/_show_partials/_show_default_metadata.html.erb +++ b/app/views/catalog/_show_partials/_show_default_metadata.html.erb @@ -252,7 +252,7 @@ <% end %> <%# additional rights/use info field %> - <% if document[:restrictions_on_access_ssm].present? %> + <% if document[:restrictions_on_access_ssm]&.first.present? %>
<%= t('blacklight.metadata_display.fields.access') %>:
<% document[:restrictions_on_access_ssm].each do |restrictions| %> diff --git a/spec/helpers/collections_helper_spec.rb b/spec/helpers/collections_helper_spec.rb index c3219179..d033cbdd 100644 --- a/spec/helpers/collections_helper_spec.rb +++ b/spec/helpers/collections_helper_spec.rb @@ -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 diff --git a/spec/vcr/CollectionsHelper/_collection_image_url/returns_the_correct_url.yml b/spec/vcr/CollectionsHelper/_collection_image_url/returns_the_correct_url.yml index ae499868..816c73b7 100644 --- a/spec/vcr/CollectionsHelper/_collection_image_url/returns_the_correct_url.yml +++ b/spec/vcr/CollectionsHelper/_collection_image_url/returns_the_correct_url.yml @@ -17,7 +17,7 @@ http_interactions: message: OK headers: Date: - - Wed, 21 Oct 2020 20:32:57 GMT + - Fri, 08 Jan 2021 15:16:16 GMT Server: - Restlet-Framework/2.3.11 Strict-Transport-Security: @@ -35,11 +35,11 @@ http_interactions: X-Powered-By: - Cantaloupe/4.0.4-SNAPSHOT Expires: - - Sun, 20 Dec 2020 20:32:57 GMT + - Tue, 09 Mar 2021 15:16:16 GMT Transfer-Encoding: - chunked body: encoding: UTF-8 string: '{"@context":"http://iiif.io/api/image/2/context.json","@id":"https://iiifdev.bpl.org/iiif/2/bpl-dev:h702q641c","protocol":"http://iiif.io/api/image","width":1496,"height":2448,"sizes":[{"width":94,"height":153},{"width":187,"height":306},{"width":374,"height":612},{"width":748,"height":1224},{"width":1496,"height":2448}],"tiles":[{"width":748,"height":1224,"scaleFactors":[1,2,4,8,16]}],"profile":["http://iiif.io/api/image/2/level2.json",{"formats":["jpg","tif","gif","png"],"maxArea":500000000,"qualities":["bitonal","default","gray","color"],"supports":["regionByPx","sizeByW","sizeByWhListed","cors","regionSquare","sizeByDistortedWh","sizeAboveFull","canonicalLinkHeader","sizeByConfinedWh","sizeByPct","jsonldMediaType","regionByPct","rotationArbitrary","sizeByH","baseUriRedirect","rotationBy90s","profileLinkHeader","sizeByForcedWh","sizeByWh","mirroring"]}]}' - recorded_at: Wed, 21 Oct 2020 20:32:57 GMT + recorded_at: Fri, 08 Jan 2021 15:16:16 GMT recorded_with: VCR 6.0.0