Class: DerivativeRodeo::Generators::ThumbnailGenerator
- Inherits:
-
BaseGenerator
- Object
- BaseGenerator
- DerivativeRodeo::Generators::ThumbnailGenerator
- Defined in:
- lib/derivative_rodeo/generators/thumbnail_generator.rb
Overview
This generator is responsible for converting a given binary into a thumbnail. As of <2023-05-22 Mon>, we’re needing to generate thumbnails for PDFs and images.
Class Attributes collapse
-
#dimensions_by_type ⇒ Hash<Symbol,String>
The “types” (as categorized by Hyrax::FileSetDerivativeService).
-
#dimensions_fallback ⇒ String
When there’s no match for #dimensions_by_type use this value.
Attributes inherited from BaseGenerator
#input_uris, #output_extension, #output_location_template, #preprocessed_location_template
Class Method Summary collapse
Instance Method Summary collapse
- #build_step(output_location:, input_tmp_file_path:) ⇒ StorageLocations::BaseLocation
-
#thumbnify(path_of_file_to_create_thumbnail_from:, path_for_thumbnail_output:) ⇒ Object
Convert the file found at :path_to_input into a thumbnail, writing it to the :path_for_thumbnail_output.
Methods inherited from BaseGenerator
#derive_preprocessed_template_from, #destination, #generated_files, #generated_uris, #initialize, #input_files, #run, #valid_instantiation?, #with_each_requisite_location_and_tmp_file_path
Constructor Details
This class inherits a constructor from DerivativeRodeo::Generators::BaseGenerator
Instance Attribute Details
#dimensions_by_type ⇒ Hash<Symbol,String>
Returns the “types” (as categorized by Hyrax::FileSetDerivativeService). These aren’t mime-types per se but a conceptual distillation of that.
26 |
# File 'lib/derivative_rodeo/generators/thumbnail_generator.rb', line 26 class_attribute :dimensions_by_type, default: { pdf: "338x493" } |
#dimensions_fallback ⇒ String
Returns when there’s no match for #dimensions_by_type use this value.
32 |
# File 'lib/derivative_rodeo/generators/thumbnail_generator.rb', line 32 class_attribute :dimensions_fallback, default: "200x150>" |
Class Method Details
.dimensions_for(filename:) ⇒ String
53 54 55 56 |
# File 'lib/derivative_rodeo/generators/thumbnail_generator.rb', line 53 def self.dimensions_for(filename:) type = DerivativeRodeo::Services::MimeTypeService.hyrax_type(filename: filename) dimensions_by_type.fetch(type, dimensions_fallback) end |
Instance Method Details
#build_step(output_location:, input_tmp_file_path:) ⇒ StorageLocations::BaseLocation
41 42 43 44 45 |
# File 'lib/derivative_rodeo/generators/thumbnail_generator.rb', line 41 def build_step(output_location:, input_tmp_file_path:, **) output_location.with_new_tmp_path do |out_tmp_path| thumbnify(path_of_file_to_create_thumbnail_from: input_tmp_file_path, path_for_thumbnail_output: out_tmp_path) end end |
#thumbnify(path_of_file_to_create_thumbnail_from:, path_for_thumbnail_output:) ⇒ Object
Convert the file found at :path_to_input into a thumbnail, writing it to the :path_for_thumbnail_output
67 68 69 70 |
# File 'lib/derivative_rodeo/generators/thumbnail_generator.rb', line 67 def thumbnify(path_of_file_to_create_thumbnail_from:, path_for_thumbnail_output:) dimensions = dimensions_for(filename: path_of_file_to_create_thumbnail_from) `convert #{path_of_file_to_create_thumbnail_from} -thumbnail '#{dimensions}' -flatten #{path_for_thumbnail_output}` end |