-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.lua
38 lines (36 loc) · 1.35 KB
/
example.lua
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
-- Example of non-animated gif:
local filename = "mini-graphics-ducks-425811.gif"
-- This .GIF was downloaded from:
-- http://www.picgifs.com/mini-graphics/mini-graphics/ducks/mini-graphics-ducks-425811.gif
--[[
-- Example of animated gif:
local filename = "mini-graphics-cats-864491.gif"
-- This .GIF was downloaded from:
-- http://www.picgifs.com/mini-graphics/mini-graphics/cats/mini-graphics-cats-864491.gif
--]]
local gif = require'gif'(filename)
local w, h = gif.get_width_height()
print('Picture dimensions: '..w..' x '..h)
print('Total Frames: '..gif.get_file_parameters().number_of_images)
print('Comment: '..(gif.get_file_parameters().comment or 'NO_COMMENT'))
print('Looped: '..(gif.get_file_parameters().looped and 'YES' or 'NO'))
repeat
local image_no = gif.get_image_parameters().image_no
print("Frame #"..image_no)
local m = gif.read_matrix()
-- Print the matrix for this frame
for row = 1, #m do
local r = {}
for col = 1, #m[1] do
local color = m[row][col]
if color == -1 then -- Transparent color
color = "------"
else -- Non-transparent color in 0xRRGGBB format
color = ("%06X"):format(color)
end
table.insert(r, color)
end
print(table.concat(r, " "))
end
until not gif.next_image() -- try to switch to next animation frame
gif.close()