Class: DerivativeRodeo::Generators::ThumbnailGenerator

Inherits:
BaseGenerator
  • Object
show all
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

Attributes inherited from BaseGenerator

#input_uris, #output_extension, #output_location_template, #preprocessed_location_template

Class Method Summary collapse

Instance Method Summary collapse

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_typeHash<Symbol,String>

Returns the “types” (as categorized by Hyrax::FileSetDerivativeService). These aren’t mime-types per se but a conceptual distillation of that.

Returns:

  • (Hash<Symbol,String>)

    the “types” (as categorized by Hyrax::FileSetDerivativeService). These aren’t mime-types per se but a conceptual distillation of that.

See Also:



26
# File 'lib/derivative_rodeo/generators/thumbnail_generator.rb', line 26

class_attribute :dimensions_by_type, default: { pdf: "338x493" }

#dimensions_fallbackString

Returns when there’s no match for #dimensions_by_type use this value.

Returns:



32
# File 'lib/derivative_rodeo/generators/thumbnail_generator.rb', line 32

class_attribute :dimensions_fallback, default: "200x150>"

Class Method Details

.dimensions_for(filename:) ⇒ String

Parameters:

  • filename (String)

Returns:

  • (String)

See Also:



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

Parameters:

Returns:



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

Parameters:

  • path_of_file_to_create_thumbnail_from (String)
  • path_for_thumbnail_output (String)


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