This repository has been archived by the owner on Feb 23, 2021. It is now read-only.
forked from slackhq/magic-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommando-ticker
80 lines (63 loc) · 2.26 KB
/
commando-ticker
1
2
3
4
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
45
46
47
48
49
50
51
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
77
78
79
80
#!/usr/bin/env ruby
require_relative 'commando-helpers.rb'
require 'chunky_png'
program :description, 'TBD'
program :version, '1.0.0'
command :loop do |c|
c.description = 'TBD'
c.option '--texture FILE'
c.option '--output DIR', String, 'Output directory'
c.option '--width String', String, 'Cropped width'
c.action do |args, options|
options.default \
texture: "./texture.png",
output: "./output",
width: "3442"
options.texture = File.expand_path(options.texture)
options.output = File.expand_path(options.output)
options.width = options.width.to_i
command_header(c, options)
if ! File.directory?(options.output)
warning "Output directory '#{options.output}' does not exist, creating it..."
Dir.mkdir(options.output)
end
texture = ChunkyPNG::Image.from_file(options.texture)
# output is bigger than input. just tile along x
if options.width > texture.width
out = ChunkyPNG::Image.new(options.width, texture.height, "ffffff")
repeat, remainder = options.width.divmod(texture.width)
repeat.times do |i|
# tile on x repeat times
out.replace!(texture, i * texture.width, 0)
# fill any remainder on last
if (i + 1) == repeat && remainder > 0
texture.crop!(0, 0, remainder, texture.height)
out.replace!(texture, options.width - remainder, 0)
end
end
filename = "0000.png"
out.save("#{options.output}/#{filename}")
puts "Wrote #{filename}..."
else
(0..texture.width).each do |i|
# create full sized out frame
out = ChunkyPNG::Image.new(texture.width, texture.height, "ffffff")
# slide head over by i
head = texture.crop(i, 0, texture.width - i, texture.height)
# place at front
out.replace!(head, 0, 0)
# crop tail with remainder i
tail = texture.crop(0, 0, i, texture.height)
# append tail after head
out.replace!(tail, texture.width - i, 0)
# crop out to options.width
out.crop!(0, 0, options.width, texture.height)
# write to disk
filename = "#{"%04d" % i}.png"
out.save("#{options.output}/#{filename}")
puts "Wrote #{filename}..."
end
end
end
end
default_command :loop