{"action":"created","issue":{"url":"https://api.github.com/repos/python-pillow/Pillow/issues/1190","labels_url":"https://api.github.com/repos/python-pillow/Pillow/issues/1190/labels{/name}","comments_url":"https://api.github.com/repos/python-pillow/Pillow/issues/1190/comments","events_url":"https://api.github.com/repos/python-pillow/Pillow/issues/1190/events","html_url":"https://github.com/python-pillow/Pillow/issues/1190","id":68220453,"number":1190,"title":"discern if an image is animated / total number of frames","user":{"login":"jvanasco","id":204779,"avatar_url":"https://avatars.githubusercontent.com/u/204779?v=3","gravatar_id":"","url":"https://api.github.com/users/jvanasco","html_url":"https://github.com/jvanasco","followers_url":"https://api.github.com/users/jvanasco/followers","following_url":"https://api.github.com/users/jvanasco/following{/other_user}","gists_url":"https://api.github.com/users/jvanasco/gists{/gist_id}","starred_url":"https://api.github.com/users/jvanasco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jvanasco/subscriptions","organizations_url":"https://api.github.com/users/jvanasco/orgs","repos_url":"https://api.github.com/users/jvanasco/repos","events_url":"https://api.github.com/users/jvanasco/events{/privacy}","received_events_url":"https://api.github.com/users/jvanasco/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-04-13T23:41:22Z","updated_at":"2015-06-08T15:19:47Z","closed_at":null,"body":"Right now it seems that the only way to tell if an image is animated is to use `seek()`\r\n\r\n    def is_animated(im):\r\n        try:\r\n            im.seek(1)\r\n            return True\r\n        except EOFError:\r\n            return False\r\n\r\nAnd the only way to get the number of frames is to iterate over the frames until an EOFError is raised, or use an ImageSequence.Iterator -- both of which require a rewind via `seek(0)`.\r\n\r\nIt would be nice if images had a property (or two), which could automate this within PIL:\r\n\r\nI'd like to suggest `Image.is_animated` and `Image.total_frames`\r\n\r\nThe reason why I suggest the two, is that `is_animated` is a trivial operation -- some formats declare that the image is animated early on, but the worst-case-scenario would only require scanning for a second frame.  I'm unfamiliar with the Pillow internals, and I don't know if iterating over all the `total_frames` would be a fast operation or not. \r\n\r\nIt's not difficult to get this information in Python scripts, but this information seems much better suited as Image properties. "},"comment":{"url":"https://api.github.com/repos/python-pillow/Pillow/issues/comments/110037108","html_url":"https://github.com/python-pillow/Pillow/issues/1190#issuecomment-110037108","issue_url":"https://api.github.com/repos/python-pillow/Pillow/issues/1190","id":110037108,"user":{"login":"jvanasco","id":204779,"avatar_url":"https://avatars.githubusercontent.com/u/204779?v=3","gravatar_id":"","url":"https://api.github.com/users/jvanasco","html_url":"https://github.com/jvanasco","followers_url":"https://api.github.com/users/jvanasco/followers","following_url":"https://api.github.com/users/jvanasco/following{/other_user}","gists_url":"https://api.github.com/users/jvanasco/gists{/gist_id}","starred_url":"https://api.github.com/users/jvanasco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jvanasco/subscriptions","organizations_url":"https://api.github.com/users/jvanasco/orgs","repos_url":"https://api.github.com/users/jvanasco/repos","events_url":"https://api.github.com/users/jvanasco/events{/privacy}","received_events_url":"https://api.github.com/users/jvanasco/received_events","type":"User","site_admin":false},"created_at":"2015-06-08T15:19:47Z","updated_at":"2015-06-08T15:19:47Z","body":"I thought `is_animated` would be useful, because you only have to seek until a second frame is found and can then stop reading.  If you're dealing with one of those movie-like gifs that are hundreds of frames, that could be potentially much easier on the resources – though the way n_frames is implemented and Pillow manages files might make an optimization like that unnecessary.  "}}