Module: Drakkon::Images::Shift

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

Overview

General Image Index Helper

Class Method Summary collapse

Class Method Details

.imagesObject



78
79
80
# File 'lib/drakkon/lib/images/shift.rb', line 78

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

.process(file, gravity, size) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/drakkon/lib/images/shift.rb', line 52

def self.process(file, gravity, size)
  image = MiniMagick::Image.open(file)
  # image << file
  # convert.colorspace('sRGB')
  # convert.fill('white')
  # convert.colorize(100)
  # convert << file
  # convert.call

  LogBot.info('Image Shift', "Shifting: #{file}")

  img = image.combine_options do |cmd|
    cmd.gravity gravity
    cmd.background 'transparent'
    cmd.splice size
  end

  img.write file

  # image.gravity gravity
  # image.background 'transparent'
  # image.splice size
  # image.call
  # image.write file
end

.promptObject



82
83
84
# File 'lib/drakkon/lib/images/shift.rb', line 82

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

.run!(args = []) ⇒ Object

TODO: Deprecate / Fix / Remove? This isn’t behaving like I expected it to getting a canvas shift



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

def self.run!(args = [])
  # Sizing
  size = if args.empty?
           prompt.ask('Shift Amount(LRxUD)? (e.g. -10x0): ')
         else
           args.shift
         end

  gravity = if args.empty?
              prompt.ask('Gravity? (west,east,north,south): ', default: 'west')
            else
              args.shift
            end

  puts <<~HELP
              Usage [WxH] [gravity]
              - Run in the directory you wish to modify the images
              - Shifts the images via MiniMagick
    #{'          '}

    Shift: Size: #{size}, Gravity: #{gravity}
              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)} Shift!? #{'(Destructive)'.pastel(:red)}"

  start(size, gravity)
end

.start(size, gravity) ⇒ Object



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

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