Class: Mayu::Resources::Generators::Image

Inherits:
Base
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/mayu/resources/generators/image.rb

Instance Method Summary collapse

Constructor Details

#initialize(source_path, version) ⇒ Image

Returns a new instance of Image.



21
22
23
24
# File 'lib/mayu/resources/generators/image.rb', line 21

def initialize(source_path, version)
  @source_path = source_path
  @version = version
end

Instance Method Details

#process(target_path) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mayu/resources/generators/image.rb', line 27

def process(target_path)
  return if File.exist?(target_path)

  require "rmagick"

  Console.logger.info(
    self,
    "Generating #{target_path} from #{@source_path}"
  )

  Magick::Image
    .read(@source_path)
    .first
    .resize_to_fit(@version.width)
    .write(target_path) { |options| options.quality = 80 }
end