Class: Epuber::Compiler::FileTypes::ImageFile

Inherits:
SourceFile show all
Defined in:
lib/epuber/compiler/file_types/image_file.rb

Instance Attribute Summary

Attributes inherited from SourceFile

#abs_source_path, #file_request, #source_path

Attributes inherited from AbstractFile

#destination_path, #final_destination_path, #group, #path_type, #pkg_destination_path, #properties

Instance Method Summary collapse

Methods inherited from SourceFile

#default_file_copy, #initialize, #write_compiled, #write_processed

Methods inherited from AbstractFile

#==, file_copy, file_copy!, file_copy?, write_to_file, write_to_file!, write_to_file?

Constructor Details

This class inherits a constructor from Epuber::Compiler::FileTypes::SourceFile

Instance Method Details

#process(compilation_context) ⇒ Object

Parameters:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/epuber/compiler/file_types/image_file.rb', line 14

def process(compilation_context)
  dest = final_destination_path
  source = abs_source_path

  return if FileUtils.uptodate?(dest, [source])

  img = Magick::Image::read(source).first

  resolution = img.columns * img.rows
  max_resolution = 3_000_000

  if resolution > max_resolution
    img = img.change_geometry("#{max_resolution}@>") do |width, height, b_img|
      UI.print_processing_debug_info("downscaling from resolution #{b_img.columns}x#{b_img.rows} to #{width}x#{height}")
      b_img.resize!(width, height)
    end

    FileUtils.mkdir_p(File.dirname(dest))

    img.write(dest)
  else
    # file is already old
    self.class.file_copy!(source, dest)
  end
end