Module: Drakkon::Images::GifSplit

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

Overview

General Image Index Helper

Class Method Summary collapse

Class Method Details

.imagesObject



48
49
50
51
52
# File 'lib/drakkon/lib/images/gif.rb', line 48

def self.images
  Dir["#{Dir.pwd}/*.gif"].map do |x|
    File.basename(x, '.gif')
  end.sort
end

.process(file, png_image) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/drakkon/lib/images/gif.rb', line 40

def self.process(file, png_image)
  LogBot.info('Gif Split', file)
  convert = MiniMagick::Tool::Convert.new
  convert << file
  convert << png_image
  convert.call
end

.promptObject



54
55
56
# File 'lib/drakkon/lib/images/gif.rb', line 54

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

def self.run!(args = [])
  image = if args.empty?
            prompt.select('What gif to split?', images, filter: true)
          else
            args.first
          end

  png_image = "#{Dir.pwd}/#{image}.png"
  image = "#{Dir.pwd}/#{image}.gif"

  unless File.exist?(image)
    LogBot.fatal('Split', "Unable to find: '#{image}'")
    exit 1
  end

  puts <<~HELP
              Usage [file]
              - Modify one gif into a directory of split images


    Split:
        Current Directory: #{Dir.pwd.pastel(:yellow)}

    Gif to Split: #{image}
  HELP

  puts

  exit unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)} Split!? #{'(Destructive)'.pastel(:red)}"

  process(image, png_image)
rescue TTY::Reader::InputInterrupt
  exit 0
end