feat(gallery): display large variant for rare image types

This commit is contained in:
Eric Leroy-Terquem 2024-05-24 09:58:19 +02:00
parent f3795ebc98
commit 05ad5dcbd6
No known key found for this signature in database
GPG key ID: ECE60B4C1FA2ABB3
6 changed files with 33 additions and 9 deletions

View file

@ -38,6 +38,9 @@ class ImageProcessorJob < ApplicationJob
blob.attachments.each do |attachment|
next unless attachment&.representable?
attachment.representation(resize_to_limit: [400, 400]).processed
if attachment.blob.content_type.in?(RARE_IMAGE_TYPES)
attachment.variant(resize_to_limit: [2000, 2000]).processed
end
end
end

View file

@ -19,7 +19,8 @@
= render Attachment::ShowComponent.new(attachment: attachment, truncate: true)
- elsif blob.variable? && blob.content_type.in?(AUTHORIZED_IMAGE_TYPES)
= link_to image_url(blob.url), title: "#{champ.libelle} -- #{blob.filename}", data: { src: blob.url }, class: 'gallery-link' do
- blob_url = blob.content_type.in?(RARE_IMAGE_TYPES) ? attachment.variant(resize_to_limit: [2000, 2000]).processed.url : blob.url
= link_to image_url(blob_url), title: "#{champ.libelle} -- #{blob.filename}", data: { src: blob.url }, class: 'gallery-link' do
.thumbnail
= image_tag(attachment.variant(resize_to_limit: [400, 400]).processed.url, loading: :lazy)
.fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button }

View file

@ -16,7 +16,8 @@
= 'Visualiser'
- elsif blob.variable? && blob.content_type.in?(AUTHORIZED_IMAGE_TYPES)
= link_to image_url(blob.url), title: "#{champ.libelle} -- #{blob.filename}", data: { src: blob.url }, class: 'gallery-link' do
- blob_url = blob.content_type.in?(RARE_IMAGE_TYPES) ? attachment.variant(resize_to_limit: [2000, 2000]).processed.url : blob.url
= link_to image_url(blob_url), title: "#{champ.libelle} -- #{blob.filename}", data: { src: blob.url }, class: 'gallery-link' do
.thumbnail
= image_tag(attachment.variant(resize_to_limit: [400, 400]).processed.url, loading: :lazy)
.fr-btn.fr-btn--tertiary.fr-btn--icon-left.fr-icon-eye{ role: :button }

View file

@ -15,6 +15,10 @@ AUTHORIZED_IMAGE_TYPES = [
'image/vnd.dwg' # multimedia x 137 auto desk
]
RARE_IMAGE_TYPES = [
'image/tiff' # multimedia x 3985
]
AUTHORIZED_CONTENT_TYPES = AUTHORIZED_IMAGE_TYPES + AUTHORIZED_PDF_TYPES + [
# multimedia
'video/mp4', # multimedia x 2075

BIN
spec/fixtures/files/pencil.tiff vendored Normal file

Binary file not shown.

View file

@ -63,7 +63,6 @@ describe ImageProcessorJob, type: :job do
end
describe 'create representation' do
let(:file) { fixture_file_upload('spec/fixtures/files/logo_test_procedure.png', 'image/png') }
let(:blob_info) do
{
filename: file.original_filename,
@ -81,6 +80,9 @@ describe ImageProcessorJob, type: :job do
blob
end
context "when type image is usual" do
let(:file) { fixture_file_upload('spec/fixtures/files/logo_test_procedure.png', 'image/png') }
context "when representation is not required" do
it "it does not create blob representation" do
expect { described_class.perform_now(blob) }.not_to change { ActiveStorage::VariantRecord.count }
@ -98,6 +100,19 @@ describe ImageProcessorJob, type: :job do
end
end
context "when type image is rare" do
let(:file) { fixture_file_upload('spec/fixtures/files/pencil.tiff', 'image/tiff') }
before do
allow(blob).to receive(:representation_required?).and_return(true)
end
it "creates a second variant" do
expect { described_class.perform_now(blob) }.to change { ActiveStorage::VariantRecord.count }.by(2)
end
end
end
describe 'watermark' do
context "when watermark is already done" do
before do