Module: Drakkon::Images::Desaturate

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

Overview

General Image Index Helper

Class Method Summary collapse

Class Method Details

.imagesObject



47
48
49
# File 'lib/drakkon/lib/images/desaturate.rb', line 47

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

.process(file) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/drakkon/lib/images/desaturate.rb', line 36

def self.process(file)
  image = MiniMagick::Image.open(file)
  LogBot.info('Image Desaturate', file)

  img = image.combine_options do |cmd|
    cmd.colorspace 'Gray'
  end

  img.write file
end

.promptObject



51
52
53
# File 'lib/drakkon/lib/images/desaturate.rb', line 51

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

.run!(_args = []) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/drakkon/lib/images/desaturate.rb', line 5

def self.run!(_args = [])
  puts <<~HELP
              Usage [WxH] [gravity]
              - Run in the directory you wish to modify the images
              - Adjust images via MiniMagick (extent)

    Desaturate:
              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)} Desaturate!? #{'(Destructive)'.pastel(:red)}"

  start
end

.startObject



29
30
31
32
33
34
# File 'lib/drakkon/lib/images/desaturate.rb', line 29

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