Create gif2spritesheet.py

This commit is contained in:
ERROR404 2022-12-19 19:13:19 +08:00 committed by GitHub
parent fce7967b57
commit ee1d5ee1ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

23
gif2spritesheet.py Normal file
View file

@ -0,0 +1,23 @@
from PIL import Image
import io,os,sys
import logging
logging.basicConfig(format='%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s',level=logging.INFO)
if __name__ == '__main__':
if len(sys.argv) < 2:
logging.fatal("Usage:python gif2spritesheet.py <inputFile> <outputFile,Option>")
else:
OUTPUT_SIZE = (48,48)
gif = Image.open(f"{sys.argv[1]}")
output = Image.new("RGBA", (OUTPUT_SIZE[0], OUTPUT_SIZE[1] * gif.n_frames))
for frame in range(0,gif.n_frames):
gif.seek(frame)
extracted_frame = gif.resize(OUTPUT_SIZE)
position = (0, OUTPUT_SIZE[0] * frame)
output.paste(extracted_frame, position)
if(len(sys.argv) >= 3):
output.save(sys.argv[2],format="PNG")
else:
output.save(f"{sys.argv[1].strip('.gif')}.png",format="PNG")
logging.info("转换完成!")