Module: Drakkon::Images::Blur

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

Overview

General Image Index Helper

Class Method Summary collapse

Class Method Details

.imagesObject



65
66
67
# File 'lib/drakkon/lib/images/blur.rb', line 65

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

.process(file, filter, size) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/drakkon/lib/images/blur.rb', line 53

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

  # Ignore if the same
  return if image.width == size.split('x', 2).first.to_i

  LogBot.info('Image Blur', "Blurring: #{file}")
  image.filter filter
  image.blur size
  image.write file
end

.promptObject



69
70
71
# File 'lib/drakkon/lib/images/blur.rb', line 69

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/drakkon/lib/images/blur.rb', line 5

def self.run!(args = [])
  # Sizing
  size = if args.empty?
           prompt.ask('Blur Size? (e.g. 20x20): ', default: '5x5')
         else
           args.shift
         end

  # TODO: Recommend as Options
  # TODO: Blur Options

  # Potentially Support Custom Filters?
  filter = if args.empty?
             'Gaussian'
           else
             args.shift
           end

  puts <<~HELP
              Usage [size] [filter = Gaussian]
              - Run in the directory you wish to modify the images
              - Blurs the images via MiniMagick

    Filter: #{filter} to Size: #{size}
              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)} Blur!? #{'(Destructive)'.pastel(:red)}"

  start(filter, size)
end

.start(filter, size) ⇒ Object



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

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