Module: Drakkon::Images::HueModulate

Defined in:
lib/drakkon/lib/images/hue_modulation.rb

Overview

Class Method Summary collapse

Class Method Details

.imagesObject



60
61
62
# File 'lib/drakkon/lib/images/hue_modulation.rb', line 60

def self.images
  Dir["#{Dir.pwd}/**/*.png"]
end

.process(file, amount) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/drakkon/lib/images/hue_modulation.rb', line 50

def self.process(file, amount)
  image = MiniMagick::Image.open(file)

  image.combine_options do |c|
    c.modulate "100,100,#{amount}"
  end

  image.write(file)
end

.promptObject



64
65
66
# File 'lib/drakkon/lib/images/hue_modulation.rb', line 64

def self.prompt
  TTY::Prompt.new(active_color: :cyan, interrupt: :exit)
end

.run!(args = []) ⇒ Object



6
7
8
9
10
11
12
13
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
39
40
41
# File 'lib/drakkon/lib/images/hue_modulation.rb', line 6

def self.run!(args = [])
  # Amount
  amount = if args.empty?
             puts 'Amount Syntax: brightness,saturation,hue'
             prompt.ask('Amount? (0..200) 100 is no change: ')
           else
             args.shift
           end

  puts <<~HELP
    Usage
    - Run in the directory you wish to modify the images
    - Hue Modulates images via MiniMagick

    Hue Modulate Amount: #{amount}
      Current Directory;
        #{Dir.pwd.pastel(:yellow)}

    Current Directory;
      #{Dir.pwd.pastel(:yellow)}

    Images:
  HELP

  images.sort.each do |img|
    img_s = img.gsub("#{Dir.pwd}/", '').pastel(:yellow)
    puts "  - #{img_s}"
  end
  puts

  unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)} Hue Modulate!? #{'(Destructive)'.pastel(:red)}"
    exit
  end

  start(amount)
end

.start(amount) ⇒ Object



43
44
45
46
47
48
# File 'lib/drakkon/lib/images/hue_modulation.rb', line 43

def self.start(amount)
  images.each do |img|
    LogBot.info('Image Mod', img)
    process(img, amount)
  end
end