drakkon 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +50 -0
- data/bin/drakkon +16 -0
- data/lib/drakkon/build.rb +126 -0
- data/lib/drakkon/cli.rb +64 -0
- data/lib/drakkon/gem/bundle.rb +116 -0
- data/lib/drakkon/gem/cli.rb +46 -0
- data/lib/drakkon/gem/configure.rb +73 -0
- data/lib/drakkon/gem/gem.rb +56 -0
- data/lib/drakkon/gem/helpers/check.rb +110 -0
- data/lib/drakkon/gem/helpers/files.rb +57 -0
- data/lib/drakkon/gem/helpers/general.rb +21 -0
- data/lib/drakkon/gem/helpers/modules.rb +51 -0
- data/lib/drakkon/gem/helpers/source.rb +43 -0
- data/lib/drakkon/gem/install.rb +24 -0
- data/lib/drakkon/init.rb +85 -0
- data/lib/drakkon/lib/hub.rb +112 -0
- data/lib/drakkon/lib/images/biggest.rb +43 -0
- data/lib/drakkon/lib/images/blur.rb +76 -0
- data/lib/drakkon/lib/images/bulk_rename.rb +86 -0
- data/lib/drakkon/lib/images/canvas.rb +74 -0
- data/lib/drakkon/lib/images/cli.rb +78 -0
- data/lib/drakkon/lib/images/desaturate.rb +58 -0
- data/lib/drakkon/lib/images/flip_flop.rb +76 -0
- data/lib/drakkon/lib/images/gif.rb +61 -0
- data/lib/drakkon/lib/images/index.rb +185 -0
- data/lib/drakkon/lib/images/list.rb +56 -0
- data/lib/drakkon/lib/images/modulate.rb +69 -0
- data/lib/drakkon/lib/images/resize.rb +83 -0
- data/lib/drakkon/lib/images/roll.rb +68 -0
- data/lib/drakkon/lib/images/rotate.rb +60 -0
- data/lib/drakkon/lib/images/scale.rb +86 -0
- data/lib/drakkon/lib/images/sepia.rb +64 -0
- data/lib/drakkon/lib/images/shift.rb +89 -0
- data/lib/drakkon/lib/images/split.rb +93 -0
- data/lib/drakkon/lib/images/spritesheet.rb +85 -0
- data/lib/drakkon/lib/images/trim.rb +56 -0
- data/lib/drakkon/lib/images/white.rb +56 -0
- data/lib/drakkon/lib/logbot.rb +86 -0
- data/lib/drakkon/lib/manifest.rb +74 -0
- data/lib/drakkon/lib/pastel.rb +49 -0
- data/lib/drakkon/lib/settings.rb +130 -0
- data/lib/drakkon/lib/shims.rb +8 -0
- data/lib/drakkon/lib/version.rb +79 -0
- data/lib/drakkon/release.rb +3 -0
- data/lib/drakkon/run/commands/images.rb +14 -0
- data/lib/drakkon/run/commands/log.rb +57 -0
- data/lib/drakkon/run/commands/restart.rb +14 -0
- data/lib/drakkon/run/helpers.rb +60 -0
- data/lib/drakkon/run/reader_shim.rb +110 -0
- data/lib/drakkon/run/tty.rb +119 -0
- data/lib/drakkon/run.rb +80 -0
- data/lib/drakkon/setup.rb +31 -0
- data/lib/drakkon/skeleton/cli.rb +46 -0
- data/lib/drakkon/skeleton/deploy.rb +105 -0
- data/lib/drakkon/skeleton/helpers/check.rb +143 -0
- data/lib/drakkon/skeleton/helpers/general.rb +21 -0
- data/lib/drakkon/skeleton/helpers/source.rb +43 -0
- data/lib/drakkon/skeleton/install.rb +31 -0
- data/lib/drakkon/skeleton/template.rb +14 -0
- data/lib/drakkon/web.rb +68 -0
- data/lib/drakkon.rb +43 -0
- metadata +302 -0
@@ -0,0 +1,78 @@
|
|
1
|
+
module Drakkon
|
2
|
+
module Images
|
3
|
+
# General Entry Point For Images Subcommand
|
4
|
+
module CLI
|
5
|
+
def self.run!(args = [])
|
6
|
+
args ||= []
|
7
|
+
cmd = if args.empty?
|
8
|
+
nil
|
9
|
+
else
|
10
|
+
args.shift.to_sym
|
11
|
+
end
|
12
|
+
start(cmd, args)
|
13
|
+
end
|
14
|
+
|
15
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
16
|
+
def self.start(cmd, args)
|
17
|
+
case cmd
|
18
|
+
when :list then Images::List.run!(args)
|
19
|
+
when :biggest then Images::Biggest.run!(args)
|
20
|
+
when :white then Images::White.run!(args)
|
21
|
+
when :resize then Images::Resize.run!(args)
|
22
|
+
when :shift then Images::Shift.run!(args)
|
23
|
+
when :roll then Images::Roll.run!(args)
|
24
|
+
when :scale then Images::Scale.run!(args)
|
25
|
+
when :flip_flop then Images::FlipFlop.run!(args)
|
26
|
+
when :rotate then Images::Rotate.run!(args)
|
27
|
+
when :canvas then Images::Canvas.run!(args)
|
28
|
+
when :blur then Images::Blur.run!(args)
|
29
|
+
when :split then Images::SplitSpriteSheet.run!(args)
|
30
|
+
when :combine then Images::SpriteSheetCombine.run!(args)
|
31
|
+
when :trim then Images::Trim.run!(args)
|
32
|
+
when :gif_split then Images::GifSplit.run!(args)
|
33
|
+
when :sepia then Images::Sepia.run!(args)
|
34
|
+
when :modulate then Images::Modulate.run!(args)
|
35
|
+
when :bulk_rename then Images::BulkRename.run!(args)
|
36
|
+
when :index then Images::Index.run!(force: true)
|
37
|
+
when :exit then exit(0)
|
38
|
+
else
|
39
|
+
start(menu, args)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
43
|
+
|
44
|
+
def self.menu
|
45
|
+
prompt.select('Image Helpers:', filter: true, per_page: 20) do |menu|
|
46
|
+
menu.choice name: 'Listing; Filter', value: :list
|
47
|
+
menu.choice name: 'Biggest: Find largest dimensions', value: :biggest
|
48
|
+
menu.choice name: 'Convert alpha to white', value: :white
|
49
|
+
menu.choice name: 'Resize WxH', value: :resize
|
50
|
+
menu.choice name: 'Scale', value: :scale
|
51
|
+
menu.choice name: 'Shift (Splice/Gravity)', value: :shift
|
52
|
+
menu.choice name: 'Roll', value: :roll
|
53
|
+
menu.choice name: 'Flip/Flop', value: :flip_flop
|
54
|
+
menu.choice name: 'Rotate', value: :rotate
|
55
|
+
menu.choice name: 'Canvas (Change/Retain)', value: :canvas
|
56
|
+
menu.choice name: 'Desaturate (Grey Colorspace)', value: :desaturate
|
57
|
+
menu.choice name: 'Blur', value: :blur
|
58
|
+
menu.choice name: 'Split SpriteSheet (split)', value: :split
|
59
|
+
menu.choice name: 'Create SpriteSheet (combine)', value: :combine
|
60
|
+
menu.choice name: 'Trim Transparency (trim)', value: :trim
|
61
|
+
menu.choice name: 'Gif Split (gif_split)', value: :gif_split
|
62
|
+
menu.choice name: 'Sepia', value: :sepia
|
63
|
+
menu.choice name: 'Modulate', value: :modulate
|
64
|
+
menu.choice name: 'Index (Re-run Index)', value: :index
|
65
|
+
menu.choice name: 'exit', value: :exit
|
66
|
+
end
|
67
|
+
rescue TTY::Reader::InputInterrupt
|
68
|
+
exit 0
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.prompt
|
72
|
+
TTY::Prompt.new(active_color: :cyan)
|
73
|
+
end
|
74
|
+
# =========================================================
|
75
|
+
end
|
76
|
+
# =========================================================
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Drakkon
|
2
|
+
module Images
|
3
|
+
# General Image Index Helper
|
4
|
+
module Desaturate
|
5
|
+
def self.run!(_args = [])
|
6
|
+
puts <<~HELP
|
7
|
+
Usage [WxH] [gravity]
|
8
|
+
- Run in the directory you wish to modify the images
|
9
|
+
- Adjust images via MiniMagick (extent)
|
10
|
+
|
11
|
+
Desaturate:
|
12
|
+
Current Directory;
|
13
|
+
#{Dir.pwd.pastel(:yellow)}
|
14
|
+
|
15
|
+
Images:
|
16
|
+
HELP
|
17
|
+
|
18
|
+
images.sort.each do |img|
|
19
|
+
img_s = img.gsub("#{Dir.pwd}/", '').pastel(:yellow)
|
20
|
+
puts " - #{img_s}"
|
21
|
+
end
|
22
|
+
puts
|
23
|
+
|
24
|
+
exit unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)} Desaturate!? #{'(Destructive)'.pastel(:red)}"
|
25
|
+
|
26
|
+
start
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.start
|
30
|
+
images.each do |img|
|
31
|
+
LogBot.info('Image Shift', img)
|
32
|
+
process(img)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.process(file)
|
37
|
+
image = MiniMagick::Image.open(file)
|
38
|
+
LogBot.info('Image Desaturate', file)
|
39
|
+
|
40
|
+
img = image.combine_options do |cmd|
|
41
|
+
cmd.colorspace 'Gray'
|
42
|
+
end
|
43
|
+
|
44
|
+
img.write file
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.images
|
48
|
+
Dir["#{Dir.pwd}/**/*.png"]
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.prompt
|
52
|
+
TTY::Prompt.new(active_color: :cyan)
|
53
|
+
end
|
54
|
+
# =========================================================
|
55
|
+
end
|
56
|
+
# =========================================================
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Drakkon
|
2
|
+
module Images
|
3
|
+
# General Image Index Helper
|
4
|
+
module FlipFlop
|
5
|
+
def self.run!(args = [])
|
6
|
+
# X
|
7
|
+
horizontal = if args.empty?
|
8
|
+
prompt.yes?('Flip Horizontally?')
|
9
|
+
else
|
10
|
+
v = args.shift.downcase
|
11
|
+
%w[yes y].include?(v)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Y
|
15
|
+
vertical = if args.empty?
|
16
|
+
prompt.yes?('Flip Vertically?')
|
17
|
+
else
|
18
|
+
v = args.shift.downcase
|
19
|
+
%w[yes y].include?(v)
|
20
|
+
end
|
21
|
+
|
22
|
+
puts <<~HELP
|
23
|
+
Usage [horizontal] [vertical]
|
24
|
+
- Run in the directory you wish to modify the images
|
25
|
+
- Flip/Flop the images via MiniMagick
|
26
|
+
- y / yes / Y / Yes for affirmative args
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
Horizontal: #{horizontal}
|
32
|
+
Vertical: #{vertical}
|
33
|
+
Current Directory;
|
34
|
+
#{Dir.pwd.pastel(:yellow)}
|
35
|
+
|
36
|
+
Images:
|
37
|
+
HELP
|
38
|
+
|
39
|
+
images.sort.each do |img|
|
40
|
+
img_s = img.gsub("#{Dir.pwd}/", '').pastel(:yellow)
|
41
|
+
puts " - #{img_s}"
|
42
|
+
end
|
43
|
+
puts
|
44
|
+
|
45
|
+
exit unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)} Flip/Flop!? #{'(Destructive)'.pastel(:red)}"
|
46
|
+
|
47
|
+
start(horizontal, vertical)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.start(horizontal, vertical)
|
51
|
+
images.each do |img|
|
52
|
+
LogBot.info('Image Flip Flop', img)
|
53
|
+
process(img, horizontal, vertical)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.process(file, horizontal, vertical)
|
58
|
+
image = MiniMagick::Image.open(file)
|
59
|
+
|
60
|
+
image.flip if vertical
|
61
|
+
image.flop if horizontal
|
62
|
+
image.write file
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.images
|
66
|
+
Dir["#{Dir.pwd}/**/*.png"]
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.prompt
|
70
|
+
TTY::Prompt.new(active_color: :cyan)
|
71
|
+
end
|
72
|
+
# =========================================================
|
73
|
+
end
|
74
|
+
# =========================================================
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Drakkon
|
2
|
+
module Images
|
3
|
+
# General Image Index Helper
|
4
|
+
module GifSplit
|
5
|
+
def self.run!(args = [])
|
6
|
+
image = if args.empty?
|
7
|
+
prompt.select('What gif to split?', images, filter: true)
|
8
|
+
else
|
9
|
+
args.first
|
10
|
+
end
|
11
|
+
|
12
|
+
png_image = "#{Dir.pwd}/#{image}.png"
|
13
|
+
image = "#{Dir.pwd}/#{image}.gif"
|
14
|
+
|
15
|
+
unless File.exist?(image)
|
16
|
+
LogBot.fatal('Split', "Unable to find: '#{image}'")
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
|
20
|
+
puts <<~HELP
|
21
|
+
Usage [file]
|
22
|
+
- Modify one gif into a directory of split images
|
23
|
+
|
24
|
+
|
25
|
+
Split:
|
26
|
+
Current Directory: #{Dir.pwd.pastel(:yellow)}
|
27
|
+
|
28
|
+
Gif to Split: #{image}
|
29
|
+
HELP
|
30
|
+
|
31
|
+
puts
|
32
|
+
|
33
|
+
exit unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)} Split!? #{'(Destructive)'.pastel(:red)}"
|
34
|
+
|
35
|
+
process(image, png_image)
|
36
|
+
rescue TTY::Reader::InputInterrupt
|
37
|
+
exit 0
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.process(file, png_image)
|
41
|
+
LogBot.info('Gif Split', file)
|
42
|
+
convert = MiniMagick::Tool::Convert.new
|
43
|
+
convert << file
|
44
|
+
convert << png_image
|
45
|
+
convert.call
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.images
|
49
|
+
Dir["#{Dir.pwd}/*.gif"].map do |x|
|
50
|
+
File.basename(x, '.gif')
|
51
|
+
end.sort
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.prompt
|
55
|
+
TTY::Prompt.new(active_color: :cyan)
|
56
|
+
end
|
57
|
+
# =========================================================
|
58
|
+
end
|
59
|
+
# =========================================================
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,185 @@
|
|
1
|
+
module Drakkon
|
2
|
+
module Images
|
3
|
+
# General Image Index Helper
|
4
|
+
module Index
|
5
|
+
def self.index
|
6
|
+
@index ||= {}
|
7
|
+
|
8
|
+
@index
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.catalog
|
12
|
+
# Better way to do this?
|
13
|
+
@catalog ||= Hash.new { |hash, key| hash[key] = Hash.new(&hash.default_proc) }
|
14
|
+
|
15
|
+
@catalog
|
16
|
+
end
|
17
|
+
|
18
|
+
# No Animations
|
19
|
+
def self.sprites
|
20
|
+
@sprites ||= {}
|
21
|
+
|
22
|
+
@sprites
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.all
|
26
|
+
@all ||= []
|
27
|
+
|
28
|
+
@all
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.context
|
32
|
+
@context ||= Dir.pwd
|
33
|
+
|
34
|
+
@context
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.digest
|
38
|
+
list = Dir["#{sprites_directory}**/*.png"]
|
39
|
+
Digest::MD5.hexdigest(list.map { |x| Digest::MD5.file(x).hexdigest }.join)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.sprites_directory
|
43
|
+
"#{context}/sprites/"
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.run!(force: false, dir: nil)
|
47
|
+
@context = dir || Dir.pwd
|
48
|
+
|
49
|
+
# Create Directory if sprites directory is missing
|
50
|
+
FileUtils.mkdir_p(sprites_directory)
|
51
|
+
|
52
|
+
if Settings.config[:image_digest] == digest
|
53
|
+
LogBot.info('Images Index', 'Nothing New')
|
54
|
+
return unless force
|
55
|
+
end
|
56
|
+
|
57
|
+
build_index
|
58
|
+
|
59
|
+
Settings.update(:image_digest, digest)
|
60
|
+
|
61
|
+
File.write("#{context}/app/drakkon/image_index.rb", result)
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.build_index
|
65
|
+
check sprites_directory
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.result
|
69
|
+
<<~RB
|
70
|
+
module Drakkon
|
71
|
+
module Images
|
72
|
+
def self.index
|
73
|
+
#{index.inspect}
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.catalog
|
77
|
+
#{catalog.inspect}
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.sprites
|
81
|
+
#{sprites.inspect}
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.reset_all
|
85
|
+
#{all.inspect}.each do |sprite|
|
86
|
+
$gtk.reset_sprite "sprites/\#{sprite}.png"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
RB
|
92
|
+
end
|
93
|
+
|
94
|
+
# Recursively Go through
|
95
|
+
def self.check(dir = nil)
|
96
|
+
LogBot.info('Image Index', "Check: #{dir}")
|
97
|
+
|
98
|
+
# Collect Images
|
99
|
+
list = Dir["#{dir}/*"]
|
100
|
+
|
101
|
+
# Ignore Empties
|
102
|
+
return if list.empty?
|
103
|
+
|
104
|
+
# Check if its an Animation Directory
|
105
|
+
if animation_directory?(list)
|
106
|
+
LogBot.info('Image Index', "Animation: #{dir}")
|
107
|
+
process_animation(list)
|
108
|
+
return
|
109
|
+
end
|
110
|
+
|
111
|
+
# Do other things
|
112
|
+
Dir["#{dir}/*"].each do |file|
|
113
|
+
if File.directory?(file)
|
114
|
+
Index.check(file)
|
115
|
+
elsif File.extname(file) == '.png'
|
116
|
+
process(file)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
:done
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.animation_directory?(list)
|
124
|
+
# Ignore Directories
|
125
|
+
return false if list.any? { |x| File.directory? x }
|
126
|
+
|
127
|
+
list.reject { |x| x.include? 'png' }.empty? && list.all? do |x|
|
128
|
+
File.basename(x).split('.png', 2).first.numeric?
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def self.process(file = nil)
|
133
|
+
details = dimensions(file)
|
134
|
+
details[:path] = file.gsub(sprites_directory, '')[1..].gsub('.png', '')
|
135
|
+
|
136
|
+
# Catalog
|
137
|
+
catalog_list = details[:path].split('/')
|
138
|
+
catalog_location = []
|
139
|
+
catalog_list.each do |idx|
|
140
|
+
catalog_location.push idx
|
141
|
+
catalog.dig(*catalog_location)
|
142
|
+
end
|
143
|
+
catalog.dig(*catalog_list).merge! details
|
144
|
+
|
145
|
+
# Full Index Push
|
146
|
+
index[details[:path]] = details
|
147
|
+
|
148
|
+
# Just Sprites Push
|
149
|
+
sprites[details[:path]] = details
|
150
|
+
|
151
|
+
all.push details[:path]
|
152
|
+
end
|
153
|
+
|
154
|
+
def self.dimensions(file)
|
155
|
+
img = MiniMagick::Image.open(file)
|
156
|
+
# data = "{ path: \"#{root}/#{file.gsub('.png', '')}\", w: #{img.width}, h: #{img.height} }"
|
157
|
+
|
158
|
+
{
|
159
|
+
w: img.width,
|
160
|
+
h: img.height
|
161
|
+
}
|
162
|
+
end
|
163
|
+
|
164
|
+
def self.process_animation(list = nil)
|
165
|
+
# Append all images to `all`
|
166
|
+
list.each do |file|
|
167
|
+
all.push file.gsub(sprites_directory, '')[1..].gsub('.png', '')
|
168
|
+
end
|
169
|
+
|
170
|
+
# Nab one to get data
|
171
|
+
file = list.first
|
172
|
+
details = dimensions(file)
|
173
|
+
|
174
|
+
# Frames and Path
|
175
|
+
details[:frames] = list.count
|
176
|
+
details[:root_path] = File.dirname(file).gsub(sprites_directory, '')[1..]
|
177
|
+
|
178
|
+
# Store via Root Path
|
179
|
+
index[details[:root_path]] = details
|
180
|
+
end
|
181
|
+
# =========================================================
|
182
|
+
end
|
183
|
+
# =========================================================
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module Drakkon
|
2
|
+
module Images
|
3
|
+
# General Image Index Helper
|
4
|
+
module List
|
5
|
+
def self.run!(args = [])
|
6
|
+
puts args
|
7
|
+
require "#{Dir.pwd}/app/drakkon/image_index"
|
8
|
+
|
9
|
+
loop do
|
10
|
+
r = listy_list(index(args))
|
11
|
+
break if r == 'exit'
|
12
|
+
|
13
|
+
puts <<~OUTPUT
|
14
|
+
|
15
|
+
#{r.pastel(:bright_blue)}
|
16
|
+
|
17
|
+
**Drakkon::Images.index['#{r}']
|
18
|
+
|
19
|
+
|
20
|
+
OUTPUT
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.index(args)
|
25
|
+
if args.empty?
|
26
|
+
|
27
|
+
Images.index.keys
|
28
|
+
else
|
29
|
+
|
30
|
+
idx = args.flat_map do |filter|
|
31
|
+
Images.index.keys.grep(/#{filter}/)
|
32
|
+
end
|
33
|
+
|
34
|
+
idx.compact.uniq
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.listy_list(list)
|
39
|
+
prompt.select('Filter:', filter: true) do |menu|
|
40
|
+
menu.choice name: 'exit'
|
41
|
+
list.each do |img|
|
42
|
+
menu.choice name: img
|
43
|
+
end
|
44
|
+
end
|
45
|
+
rescue TTY::Reader::InputInterrupt
|
46
|
+
exit 0
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.prompt
|
50
|
+
TTY::Prompt.new(active_color: :cyan)
|
51
|
+
end
|
52
|
+
# =========================================================
|
53
|
+
end
|
54
|
+
# =========================================================
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Drakkon
|
2
|
+
module Images
|
3
|
+
# General Image Index Helper
|
4
|
+
# https://imagemagick.org/script/command-line-options.php#modulate
|
5
|
+
module Modulate
|
6
|
+
def self.run!(args = [])
|
7
|
+
# Amount
|
8
|
+
amount = if args.empty?
|
9
|
+
puts 'Amount Syntax: brightness,saturation,hue'
|
10
|
+
prompt.ask('Amount? (e.g. 100,20): ')
|
11
|
+
else
|
12
|
+
args.shift
|
13
|
+
end
|
14
|
+
|
15
|
+
puts <<~HELP
|
16
|
+
Usage
|
17
|
+
- Run in the directory you wish to modify the images
|
18
|
+
- Modulates images via MiniMagick
|
19
|
+
-modulate 100,50,80
|
20
|
+
|
21
|
+
|
22
|
+
Modulate Amount: #{amount}
|
23
|
+
Current Directory;
|
24
|
+
#{Dir.pwd.pastel(:yellow)}
|
25
|
+
|
26
|
+
Current Directory;
|
27
|
+
#{Dir.pwd.pastel(:yellow)}
|
28
|
+
|
29
|
+
Images:
|
30
|
+
HELP
|
31
|
+
|
32
|
+
images.sort.each do |img|
|
33
|
+
img_s = img.gsub("#{Dir.pwd}/", '').pastel(:yellow)
|
34
|
+
puts " - #{img_s}"
|
35
|
+
end
|
36
|
+
puts
|
37
|
+
|
38
|
+
exit unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)} Modulate!? #{'(Destructive)'.pastel(:red)}"
|
39
|
+
|
40
|
+
start(amount)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.start(amount)
|
44
|
+
images.each do |img|
|
45
|
+
LogBot.info('Image Mod', img)
|
46
|
+
process(img, amount)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.process(file, amount)
|
51
|
+
convert = MiniMagick::Tool::Convert.new
|
52
|
+
convert << file
|
53
|
+
convert.modulate(amount)
|
54
|
+
convert << file
|
55
|
+
convert.call
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.images
|
59
|
+
Dir["#{Dir.pwd}/**/*.png"]
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.prompt
|
63
|
+
TTY::Prompt.new(active_color: :cyan)
|
64
|
+
end
|
65
|
+
# =========================================================
|
66
|
+
end
|
67
|
+
# =========================================================
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Drakkon
|
2
|
+
module Images
|
3
|
+
# General Image Index Helper
|
4
|
+
module Resize
|
5
|
+
def self.run!(args = [])
|
6
|
+
# Sizing
|
7
|
+
size = if args.empty?
|
8
|
+
prompt.ask('Target Size? (e.g. 200x200): ')
|
9
|
+
else
|
10
|
+
args.shift
|
11
|
+
end
|
12
|
+
|
13
|
+
# Recommend as Options?
|
14
|
+
# image.filter 'Sinc'
|
15
|
+
# image.filter 'Gaussian'
|
16
|
+
|
17
|
+
# Potentially Support Custom Filters?
|
18
|
+
filter = if args.empty?
|
19
|
+
'Lanczos2'
|
20
|
+
else
|
21
|
+
args.shift
|
22
|
+
end
|
23
|
+
|
24
|
+
puts <<~HELP
|
25
|
+
Usage [size] [filter = Lanczos2]
|
26
|
+
- Run in the directory you wish to modify the images
|
27
|
+
- Resizes the images via MiniMagick
|
28
|
+
- Sizes are #{'width'.pastel(:blue)} x #{'height'.pastel(:blue)}
|
29
|
+
- 200x200, 150,175, and etc
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
#{'Note: this will be best fit! This will retain aspect ratio!'.pastel(:bright_blue)}
|
34
|
+
|
35
|
+
Filter: #{filter} to Size: #{size}
|
36
|
+
Current Directory;
|
37
|
+
#{Dir.pwd.pastel(:yellow)}
|
38
|
+
|
39
|
+
Images:
|
40
|
+
HELP
|
41
|
+
|
42
|
+
images.sort.each do |img|
|
43
|
+
img_s = img.gsub("#{Dir.pwd}/", '').pastel(:yellow)
|
44
|
+
puts " - #{img_s}"
|
45
|
+
end
|
46
|
+
puts
|
47
|
+
|
48
|
+
exit unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)} Resize!? #{'(Destructive)'.pastel(:red)}"
|
49
|
+
|
50
|
+
start(filter, size)
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.start(filter, size)
|
54
|
+
images.each do |img|
|
55
|
+
LogBot.info('Image Resize', img)
|
56
|
+
process(img, filter, size)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.process(file, filter, size)
|
61
|
+
image = MiniMagick::Image.open(file)
|
62
|
+
|
63
|
+
# Ignore if the same for w/h
|
64
|
+
return if image.width == size.split('x', 2).first.to_i && image.height == size.split('x', 2).last.to_i
|
65
|
+
|
66
|
+
LogBot.info('Image Resize', "Resizing: #{file}: #{size}")
|
67
|
+
image.filter filter
|
68
|
+
image.resize size
|
69
|
+
image.write file
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.images
|
73
|
+
Dir["#{Dir.pwd}/**/*.png"]
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.prompt
|
77
|
+
TTY::Prompt.new(active_color: :cyan)
|
78
|
+
end
|
79
|
+
# =========================================================
|
80
|
+
end
|
81
|
+
# =========================================================
|
82
|
+
end
|
83
|
+
end
|