Module: Drakkon::Images::Trim

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

Overview

General Image Index Helper

Class Method Summary collapse

Class Method Details

.imagesObject



45
46
47
# File 'lib/drakkon/lib/images/trim.rb', line 45

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

.process(file) ⇒ Object



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

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

  LogBot.info('Image Trim', File.basename(file).to_s)
  image.trim
  image.repage
  image.write output_file
end

.promptObject



49
50
51
# File 'lib/drakkon/lib/images/trim.rb', line 49

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
28
# File 'lib/drakkon/lib/images/trim.rb', line 5

def self.run!(_args = [])
  puts <<~HELP
              Usage
              - Run in the directory you wish to modify the images
              - Trim/Repage the images via MiniMagick
    #{'          '}
            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)} Scale Images!? #{'(Destructive)'.pastel(:red)}"
    exit
  end

  start
end

.startObject



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

def self.start
  images.each do |img|
    process(img)
  end
end