omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Support for animated gifs in scene module?

    Pythonista
    scene gif
    5
    11
    7209
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Kamozo
      Kamozo last edited by ccc

      Hi, I was wondering if the scene module supported gifs. I've tried using them in my own project but they are just a still image.
      Here's some example code so you can see what I'm trying to do:

      from scene import *
      class MyScene (Scene):
          def setup(self):
              self.background_color = 'midnightblue'
              self.ship = SpriteNode('ship.GIF') #Why won't it play?
              self.ship.position = self.size / 2
              self.add_child(self.ship)
      run(MyScene())
      

      Help would be appreciated, thanks.

      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        Animated gifs are not supported in scene, though webview supports them.
        You could split the gif into images, and then animate them yourself.

        1 Reply Last reply Reply Quote 0
        • Kamozo
          Kamozo last edited by

          Oh, okay. It'd be cool if they were. Perhaps maybe in a future version.
          I've tried splitting them, but I don't know how to make it continuously repeat.

          1 Reply Last reply Reply Quote 0
          • ccc
            ccc last edited by

            https://forum.omz-software.com/topic/2052/gif-art-in-python

            1 Reply Last reply Reply Quote 0
            • Kamozo
              Kamozo last edited by

              That's useful, but what if I wanted to animate a gif using the scene module only, with my own images? Would that be possible?

              1 Reply Last reply Reply Quote 0
              • brumm
                brumm last edited by

                The scene draw method is called up to 60 times per second. So your code should not need more than 1/60s or you reduce the interval. However first you should read your images to the memory. Last tip https://github.com/humberry/scene-tutorial/

                1 Reply Last reply Reply Quote 0
                • abcabc
                  abcabc last edited by

                  Here is the code to animate gif file in scene.
                  https://gist.github.com/balachandrana/c1580fff9477d58fd0cf25c898471597

                  The frame rate may be low in slower machines. and the frame rate could be improved by caching.

                  1 Reply Last reply Reply Quote 1
                  • ccc
                    ccc last edited by

                    @abcabc Great stuff! Comments on the gist.

                    1 Reply Last reply Reply Quote 0
                    • abcabc
                      abcabc last edited by

                      @ccc Thanks for the suggestions. As suggested by you, I updated the code to use seek(0) instead of closing and opening files. It is a good suggestion although it did not improve the speed much. I will implement the caching and will also put the code in github so that you can do the pull request. I will also use the imagesequence rather than seek and tell.

                      1 Reply Last reply Reply Quote 0
                      • JonB
                        JonB last edited by JonB

                        I would think I would be better to pre-load the images into a list of ui.Images, that way you don't waste time converting. Also, BytesIO works well for saving data to avoid disk usage. Image.from_data reads from a bytesio.

                        1 Reply Last reply Reply Quote 0
                        • abcabc
                          abcabc last edited by

                          @JonB Thanks for the suggestions. Created a GifSpriteNode class which could be used like SpriteNode. Added support for duration. Used BytesIO instead of files. Added preload option. Here is the git repository
                          https://github.com/balachandrana/animating_gif_in_pythonista_scene.git

                          It does not seem to work for all gifs. There is no straight-forward PIL API to take care of all situations. Tried some solutions suggested on stackoverflow and other web sites but still all gifs do not work. Anyway I will try to see what could be done.

                          1 Reply Last reply Reply Quote 1
                          • First post
                            Last post
                          Powered by NodeBB Forums | Contributors