forked from educ8s/Python-GIF-to-Sprite-sheet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
26 lines (20 loc) · 801 Bytes
/
main.py
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
from PIL import Image
OUTPUT_SIZE = (64,64) # The output size of each frame (or tile or Sprite) of the animation
FILENAME = "clock.gif" # The file to convert
MONOCHROME = False # Do you want the output file to be b/w?
gif = Image.open(FILENAME)
print(f"Size: {gif.size}")
print(f"Frames: {gif.n_frames}")
if MONOCHROME:
output = Image.new("1", (OUTPUT_SIZE[0] * gif.n_frames, OUTPUT_SIZE[1]), 0)
else:
output = Image.new("RGB", (OUTPUT_SIZE[0] * gif.n_frames, OUTPUT_SIZE[1]))
output_filename = f"icon_{gif.n_frames}_frames.bmp"
for frame in range(0,gif.n_frames):
gif.seek(frame)
extracted_frame = gif.resize(OUTPUT_SIZE)
position = (OUTPUT_SIZE[0]*frame, 0)
output.paste(extracted_frame, position)
if not MONOCHROME:
output = output.convert("P", colors = 8)
output.save(output_filename)