Previously, I wrote Articles I was addicted to with GIF animation, but I was interested in ** disassembling GIF animation ** during my research at that time. just made it.
This was made up of ** Image Sequence ** inside ** PIL **. By the way, I made it a specification to call from the shared sheet of iOS.
gif2png
import appex
import console
import photos
import tempfile
from PIL import Image
from PIL import ImageSequence
def main():
if not appex.is_running_extension():
console.hud_alert('Please execute from the shared sheet.',icon='error',duration=2)
return
FilePath = appex.get_image().filename
if not FilePath:
console.hud_alert('GIF image not found.',icon='error',duration=2)
return
gif = Image.open(FilePath)
for i,img in enumerate(ImageSequence.Iterator(gif)):
SaveName = tempfile.gettempdir()+'/tmp.png'
img.save(SaveName)
photos.create_image_asset(SaveName)
console.hud_alert(str(i+1)+'I saved the image in the photo.', icon='success', duration=2)
appex.finish()
if __name__ == '__main__':
main()
Register and use ** Share Extension Shortcuts ** of ** Pythonista3 **. [IOS] Use shared sheet with Pythonista3. --Qiita
If ** Pythonista3 ** is installed, tap the ** Share Menu ** icon from the photo app etc. to display the ** Run Pythonista Script ** menu. Just tap here and tap the pre-registered script icon.
Recommended Posts