Module: Drakkon::Images::Sepia

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

Overview

Class Method Summary collapse

Class Method Details

.imagesObject



53
54
55
# File 'lib/drakkon/lib/images/sepia.rb', line 53

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

.process(file, amount) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/drakkon/lib/images/sepia.rb', line 44

def self.process(file, amount)
  convert = MiniMagick::Tool::Convert.new
  convert << file
  convert.colorspace('RGB')
  convert.sepia_tone("#{amount}%")
  convert << file
  convert.call
end

.promptObject



57
58
59
# File 'lib/drakkon/lib/images/sepia.rb', line 57

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
# File 'lib/drakkon/lib/images/sepia.rb', line 6

def self.run!(args = [])
  # Amount
  amount = if args.empty?
             prompt.ask('Sepia Threshold? (e.g. 80): ')
           else
             args.shift
           end

  puts <<~HELP
    Usage
    - Run in the directory you wish to modify the images
    - Applies a special effect to the image, similar to the effect achieved in a photo darkroom by sepia toning.

    Sepia: Amount: #{amount}
    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

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

  start(amount)
end

.start(amount) ⇒ Object



37
38
39
40
41
42
# File 'lib/drakkon/lib/images/sepia.rb', line 37

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