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
|
#!/usr/bin/env lua
local input = arg[1] or "$1"
local output = arg[2] or "$2"
local squish = 1.25
local scale = 0.875
local delay = 60
local flip = false
local sprite = { x = 14, y = 20, w = 112, h = 112 }
local frames = {
{ x = 0, y = 0, w = 0, h = 0 },
{ x = -4, y = 12, w = 4, h = -12 },
{ x = -12, y = 18, w = 12, h = -18 },
{ x = -8, y = 12, w = 4, h = -12 },
{ x = -4, y = 0, w = 0, h = 0 },
}
local hand = { w = 112, h = 112 }
local cmd = {}
for i, f in ipairs(frames) do
local x, y, w, h =
math.floor(sprite.x + f.x * squish * 0.4),
math.floor(sprite.y + f.y * squish * 0.9),
math.floor((sprite.w + f.w * squish) * scale),
math.floor((sprite.h + f.h * squish) * scale)
local hand_y = math.max(0, math.floor(y * 0.75 - math.max(0, sprite.y) - 0.5))
table.insert(cmd,
("\tmagick -size %dx%d xc:transparent"
.." \\( \"%s\" %s -resize %dx%d! -geometry +%d+%d \\) -composite"
.." \\( hand.png -crop %dx%d+%d+%d -geometry +%d+%d \\) -composite"
.." -depth 8 rgba:-\n")
:format(sprite.w, sprite.h,
input, flip and "-flop" or "", w, h, x, y,
hand.w, hand.h, (i-1)*hand.w, 0, 0, hand_y))
end
print(
("(\n%s) | ffmpeg -hide_banner -loglevel error"
.." -f rawvideo -pixel_format rgba -video_size %dx%d -framerate %f -i -"
.." -f gif -filter_complex 'split[v],palettegen,[v]paletteuse' -y \"%s\"")
:format(table.concat(cmd), sprite.w, sprite.h, 1000/delay, output))
|