Skip to content

Instantly share code, notes, and snippets.

@YuheiNakasaka
Created August 5, 2014 14:15
Show Gist options
  • Select an option

  • Save YuheiNakasaka/734ba2626aa7bf66741f to your computer and use it in GitHub Desktop.

Select an option

Save YuheiNakasaka/734ba2626aa7bf66741f to your computer and use it in GitHub Desktop.
pythonのgifparser
from pprint import pprint
import requests
gif_bytes = requests.get("http://imgs.xkcd.com/comics/frequency/heartbeat.gif").content
import gifparse
gif = gifparse.parse(gif_bytes)
pprint(gif.__dict__)
# output
'''
{'application_extensions': [<gifparse.blocks.ApplicationExtension object at 0x103b2f8d0>,
<gifparse.blocks.ApplicationExtension object at 0x103b2f950>,
<gifparse.blocks.ApplicationExtension object at 0x103b2fa10>,
<gifparse.blocks.ApplicationExtension object at 0x103b2fad0>,
<gifparse.blocks.ApplicationExtension object at 0x103b2fb90>,
<gifparse.blocks.ApplicationExtension object at 0x103b2fc50>,
<gifparse.blocks.ApplicationExtension object at 0x103b2fd10>,
<gifparse.blocks.ApplicationExtension object at 0x103b2fdd0>,
<gifparse.blocks.ApplicationExtension object at 0x103b2fe90>,
<gifparse.blocks.ApplicationExtension object at 0x103b2ff50>,
<gifparse.blocks.ApplicationExtension object at 0x103b4e050>,
<gifparse.blocks.ApplicationExtension object at 0x103b4e110>,
<gifparse.blocks.ApplicationExtension object at 0x103b4e1d0>,
<gifparse.blocks.ApplicationExtension object at 0x103b4e290>,
<gifparse.blocks.ApplicationExtension object at 0x103b4e350>,
<gifparse.blocks.ApplicationExtension object at 0x103b4e410>,
<gifparse.blocks.ApplicationExtension object at 0x103b4e4d0>],
'comment_extensions': [],
'frames': [{'gce': <gifparse.blocks.GraphicsControlExtension object at 0x103b2f890>,
'image_block': <gifparse.blocks.ImageBlock object at 0x103b2f910>},
{'gce': <gifparse.blocks.GraphicsControlExtension object at 0x103b2f990>,
'image_block': <gifparse.blocks.ImageBlock object at 0x103b2f9d0>},
{'gce': <gifparse.blocks.GraphicsControlExtension object at 0x103b2fa50>,
'image_block': <gifparse.blocks.ImageBlock object at 0x103b2fa90>},
{'gce': <gifparse.blocks.GraphicsControlExtension object at 0x103b2fb10>,
'image_block': <gifparse.blocks.ImageBlock object at 0x103b2fb50>},
{'gce': <gifparse.blocks.GraphicsControlExtension object at 0x103b2fbd0>,
'image_block': <gifparse.blocks.ImageBlock object at 0x103b2fc10>},
{'gce': <gifparse.blocks.GraphicsControlExtension object at 0x103b2fc90>,
'image_block': <gifparse.blocks.ImageBlock object at 0x103b2fcd0>},
{'gce': <gifparse.blocks.GraphicsControlExtension object at 0x103b2fd50>,
'image_block': <gifparse.blocks.ImageBlock object at 0x103b2fd90>},
{'gce': <gifparse.blocks.GraphicsControlExtension object at 0x103b2fe10>,
'image_block': <gifparse.blocks.ImageBlock object at 0x103b2fe50>},
{'gce': <gifparse.blocks.GraphicsControlExtension object at 0x103b2fed0>,
'image_block': <gifparse.blocks.ImageBlock object at 0x103b2ff10>},
{'gce': <gifparse.blocks.GraphicsControlExtension object at 0x103b2ff90>,
'image_block': <gifparse.blocks.ImageBlock object at 0x103b2ffd0>},
{'gce': <gifparse.blocks.GraphicsControlExtension object at 0x103b4e090>,
'image_block': <gifparse.blocks.ImageBlock object at 0x103b4e0d0>},
{'gce': <gifparse.blocks.GraphicsControlExtension object at 0x103b4e150>,
'image_block': <gifparse.blocks.ImageBlock object at 0x103b4e190>},
{'gce': <gifparse.blocks.GraphicsControlExtension object at 0x103b4e210>,
'image_block': <gifparse.blocks.ImageBlock object at 0x103b4e250>},
{'gce': <gifparse.blocks.GraphicsControlExtension object at 0x103b4e2d0>,
'image_block': <gifparse.blocks.ImageBlock object at 0x103b4e310>},
{'gce': <gifparse.blocks.GraphicsControlExtension object at 0x103b4e390>,
'image_block': <gifparse.blocks.ImageBlock object at 0x103b4e3d0>},
{'gce': <gifparse.blocks.GraphicsControlExtension object at 0x103b4e450>,
'image_block': <gifparse.blocks.ImageBlock object at 0x103b4e490>}],
'global_color_table': <gifparse.blocks.GlobalColorTable object at 0x103b2f110>,
'header': <gifparse.blocks.Header object at 0x1036bbf90>,
'io': <_io.BytesIO object at 0x1039fd230>,
'screen_desc': <gifparse.blocks.LogicalScreenDescriptor object at 0x1036c5450>,
'trailer': <gifparse.blocks.Trailer object at 0x103b4e510>}
'''
@YuheiNakasaka
Copy link
Copy Markdown
Author

これ。便利そう。
jsvine/gifparse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment