|
@@ -46,6 +46,16 @@ def analyzeANIFile(filePath):
|
|
nowSize += subChunkSize
|
|
nowSize += subChunkSize
|
|
return {"code":0,"msg":frameList,"frameRate":frameRate}
|
|
return {"code":0,"msg":frameList,"frameRate":frameRate}
|
|
|
|
|
|
|
|
+def CURPaletteFix(image):
|
|
|
|
+ # type: (Image.ImageFile.ImageFile) -> None
|
|
|
|
+ if (image.mode == 'P'):
|
|
|
|
+ palette = list(image.palette.getdata()[1])
|
|
|
|
+ for i in range(4, len(palette), 4):
|
|
|
|
+ if sum(palette[i:i + 3]) == 0:
|
|
|
|
+ break
|
|
|
|
+ palette[i + 3] = 255
|
|
|
|
+ image.putpalette(palette, 'BGRA')
|
|
|
|
+
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
if len(sys.argv) < 2:
|
|
if len(sys.argv) < 2:
|
|
logging.fatal("Usage:python ani2gif.py <inputFile> <outputFile,Option>")
|
|
logging.fatal("Usage:python ani2gif.py <inputFile> <outputFile,Option>")
|
|
@@ -55,8 +65,9 @@ if __name__ == '__main__':
|
|
if res["code"] == 0:
|
|
if res["code"] == 0:
|
|
logging.info('ANI文件分析完成,帧提取完成!')
|
|
logging.info('ANI文件分析完成,帧提取完成!')
|
|
for frame in res["msg"]:
|
|
for frame in res["msg"]:
|
|
- frameImage = Image.open(io.BytesIO(frame),formats=['CUR']).convert('RGBA')
|
|
|
|
- GIFframes.append(frameImage)
|
|
|
|
|
|
+ frameImage = Image.open(io.BytesIO(frame),formats=['CUR'])
|
|
|
|
+ CURPaletteFix(frameImage)
|
|
|
|
+ GIFframes.append(frameImage.convert('RGBA'))
|
|
if(len(sys.argv) >= 3):
|
|
if(len(sys.argv) >= 3):
|
|
GIFframes[0].save(sys.argv[2],format="GIF",save_all=True, append_images=GIFframes[1:], optimize=False, duration=res["frameRate"], loop=0, transparency=0, disposal=2)
|
|
GIFframes[0].save(sys.argv[2],format="GIF",save_all=True, append_images=GIFframes[1:], optimize=False, duration=res["frameRate"], loop=0, transparency=0, disposal=2)
|
|
else:
|
|
else:
|