Skip to content

Commit

Permalink
add density to fix issue of thumbnails being too small
Browse files Browse the repository at this point in the history
  • Loading branch information
stkenny committed Dec 10, 2024
1 parent 979ccb2 commit 3706837
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/overrides/derivatives_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def create_derivatives(_filename)
Hydra::Derivatives::PdfDerivatives.create(self, source: :content,
outputs: [
{ label: :thumbnail_medium, format: 'jpg', size: '200', trim: 'true', object: self.digital_object.alternate_id, file: self.alternate_id, layer: 0 },
{ label: :thumbnail_large, format: 'jpg', size: '400', trim: 'true', object: self.digital_object.alternate_id, file: self.alternate_id, layer: 0 },
{ label: :thumbnail_large, format: 'jpg', density: 72, size: '400', trim: 'true', object: self.digital_object.alternate_id, file: self.alternate_id, layer: 0 },
{ label: :lightbox_format, format: 'jpg', size: '600', object: self.digital_object.alternate_id, file: self.alternate_id, layer: 0 },
{ label: :full_size_web_format, format: 'jpg', size: '100%', object: self.digital_object.alternate_id, file: self.alternate_id, layer: 0 },
{ label: :crop16_9_width_200_thumbnail, size: '200', crop: '200x113+0+0', gravity: "Center", trim: true, object: self.digital_object.alternate_id, file: self.alternate_id, layer: 0 }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
require "hydra/derivatives/runners/image_derivatives"
require "hydra/derivatives/runners/video_derivatives"
require "hydra/derivatives/runners/document_derivatives"

Hydra::Derivatives::ImageDerivatives.class_eval do
def self.processor_class
DRI::Derivatives::Processors::Image
Expand All @@ -18,4 +14,4 @@ def self.processor_class
def self.processor_class
DRI::Derivatives::Processors::Document
end
end
end
16 changes: 7 additions & 9 deletions config/initializers/hydra_derivatives_config.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
require 'hydra/derivatives'
require 'dri/derivatives/services/local_file_source_file'
require 'dri/derivatives/services/persist_s3_output_file'

Hydra::Derivatives.libreoffice_path = Settings.plugins.libreoffice_path
Hydra::Derivatives.source_file_service = DRI::Derivatives::Services::LocalFileSourceFile
Hydra::Derivatives.output_file_service = DRI::Derivatives::Services::PersistS3OutputFile
Hydra::Derivatives::Processors::Video::Processor.config.mpeg4.codec = '-vcodec libx264'
Hydra::Derivatives::Processors::Video::Processor.config.size_attributes = 'scale="trunc(oh*a/2)*2:480"'
ActiveSupport::Reloader.to_prepare do
Hydra::Derivatives.libreoffice_path = Settings.plugins.libreoffice_path
Hydra::Derivatives.source_file_service = DRI::Derivatives::Services::LocalFileSourceFile
Hydra::Derivatives.output_file_service = DRI::Derivatives::Services::PersistS3OutputFile
Hydra::Derivatives::Processors::Video::Processor.config.mpeg4.codec = '-vcodec libx264'
Hydra::Derivatives::Processors::Video::Processor.config.size_attributes = 'scale="trunc(oh*a/2)*2:480"'
end
5 changes: 5 additions & 0 deletions lib/dri/derivatives/processors/image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Image < Hydra::Derivatives::Processors::Image
def create_resized_image
create_image do |xfrm|
if size
xfrm.density(density) if density
xfrm.combine_options do |i|
i.flatten
i.resize(size)
Expand Down Expand Up @@ -52,6 +53,10 @@ def crop
directives.fetch(:crop, nil)
end

def density
directives.fetch(:density, nil)
end

def gravity
directives.fetch(:gravity, nil)
end
Expand Down

0 comments on commit 3706837

Please sign in to comment.