mirror of
https://mikeslab.dix.asia/gogs/My-Mods/ANI2Cape.git
synced 2025-10-01 23:14:57 +00:00
Create gif2spritesheet.py
This commit is contained in:
parent
fce7967b57
commit
ee1d5ee1ae
1 changed files with 23 additions and 0 deletions
23
gif2spritesheet.py
Normal file
23
gif2spritesheet.py
Normal 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("转换完成!")
|
Loading…
Add table
Add a link
Reference in a new issue