def export_gif(image, path, bin_file, pretext=""):
"""
Create a PNG image based on a GIF image.
The GIF data is specified in the dictionary image and contains formatted
data based on the wdb structure. The PNG image is saved to path.
"""
gif_name = get_raw(image["gif_name"], bin_file)
width = get_raw(image["width"], bin_file)
height = get_raw(image["height"], bin_file)
num_colors = get_raw(image["num_colors"], bin_file)
colors = []
for color in image["colors"]:
r = get_raw(color["r"], bin_file)
g = get_raw(color["g"], bin_file)
b = get_raw(color["b"], bin_file)
colors.append((r, g, b))
rows = []
y = 0
for row in image["rows"]:
x = 0
rows.append([])
for pixel in row["pixels"]:
color_index = get_raw(pixel["color_index"], bin_file)
c = colors[color_index]
for i in range(3):
rows[y].append(c[i])
x += 1
y += 1
#write png
f = open(path + "/" + pretext + gif_name[:-4] + ".png", "wb")
f.truncate()
w = png.Writer(width, height)
w.write(f, rows)
f.close()
评论列表
文章目录