Sha256: ae6e03a90adde811c4ed4effc352cb767949a1600461da61392e123130f7919d

Contents?: true

Size: 1.09 KB

Versions: 15

Compression:

Stored size: 1.09 KB

Contents

# encoding: utf-8

require 'rmagick'


module Epuber
  class Compiler
    module FileTypes
      require_relative 'source_file'

      class ImageFile < SourceFile
        # @param [Compiler::CompilationContext] _compilation_context
        #
        def process(_compilation_context)
          return if destination_file_up_to_date?

          dest = final_destination_path
          source = abs_source_path

          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

          update_metadata!
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
epuber-0.6.0 lib/epuber/compiler/file_types/image_file.rb
epuber-0.5.7 lib/epuber/compiler/file_types/image_file.rb
epuber-0.5.6 lib/epuber/compiler/file_types/image_file.rb
epuber-0.5.5 lib/epuber/compiler/file_types/image_file.rb
epuber-0.5.4 lib/epuber/compiler/file_types/image_file.rb
epuber-0.5.3 lib/epuber/compiler/file_types/image_file.rb
epuber-0.5.2 lib/epuber/compiler/file_types/image_file.rb
epuber-0.5.1 lib/epuber/compiler/file_types/image_file.rb
epuber-0.5.0 lib/epuber/compiler/file_types/image_file.rb
epuber-0.5.0.beta.5 lib/epuber/compiler/file_types/image_file.rb
epuber-0.5.0.beta.4 lib/epuber/compiler/file_types/image_file.rb
epuber-0.5.0.beta.3 lib/epuber/compiler/file_types/image_file.rb
epuber-0.5.0.beta.2 lib/epuber/compiler/file_types/image_file.rb
epuber-0.5.0.beta lib/epuber/compiler/file_types/image_file.rb
epuber-0.4.0 lib/epuber/compiler/file_types/image_file.rb