Module: Drakkon::Images::Rotate

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

Overview

General Image Index Helper

Class Method Summary collapse

Class Method Details

.imagesObject



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

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

.process(file, angle) ⇒ Object



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

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

  image.rotate(angle)
  image.write file
end

.promptObject



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

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

def self.run!(args = [])
  # Rotate
  angle = if args.empty?
            prompt.ask('Rotate Angle? (e.g. 90,180,45): ')
          else
            args.shift
          end

  puts <<~HELP
              Usage [angle]
              - Run in the directory you wish to modify the images
              - Rotate the images via MiniMagick
              - y / yes / Y / Yes for affirmative args

    Angle: #{angle}

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

  start(angle)
end

.start(angle) ⇒ Object



35
36
37
38
39
40
# File 'lib/drakkon/lib/images/rotate.rb', line 35

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