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.


    Display gif

    Pythonista
    4
    21
    12840
    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.
    • NoBetterName
      NoBetterName last edited by ccc

      Hello everybody...

      I have a gif saved in Pythonista that I would like to display as a SpriteNode in a scene. Is this even possible? It won't play in quicklook, so I'm not even sure if it is properly registering as a gif. The photos application will not play it either. Any help?

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

        https://forum.omz-software.com/topic/3275/recording-scene-programs-as-an-animated-gif-image led me to https://github.com/balachandrana/animating_gif_in_pythonista_scene

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

          I know about that; I did a little bit of my own research before asking here. However, I'm not sure that this is what I'm looking for. My dilemma is not only using the gif as a SpriteNode, but also saving it in Pythonista. This seems rather complicated. QuickLook won't play the gif, leading me to believe that it isn't even stored right in Pythonista. It is a simple horse gif that I saved off of the internet. I have it saved as horsegif.gif, and the app recognizes it as a gif file. What am I still doing wrong?

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

            Open the gif using ui.WebView, using abspath. If it is valid, you should be able to see it.

            import ui
            w=ui.WebView()
            filename=os.path.abspath('horsegif.gif')
            if not (os.path.exists(filename)):
                raise FileNotFoundError('This file does exist!')
            w.load_url(filename)
            present()
            

            If you get no errors, but the file still does not display, the question becomes how did you save it and how did you get it into pythonista? If you tried to use urllib for example, a common problem is using text rather than binary file modes.

            cvp 1 Reply Last reply Reply Quote 0
            • NoBetterName
              NoBetterName last edited by NoBetterName

              No, I tried downloading it in two ways...

              1. Copy the image. Use the clipboard module to save the copied file. It displays the gif animation on Safari, but not in Pythonista.
              2. Save the image to Camera Roll, the use photos module to import it into Pythonista. Same results.

              The file exists in Pythonista, but the animation is not there.

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

                I tried your method, and a still picture of the first frame of the gif displays. Your final question is similar to what I originally meant, though I probably didn't say it correctly. I was just trying to figure out what I did wrong with the saving. I know it is a valid file, and that when I save it in Pythonista it does not animate.

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

                  Is it possible to post here the URL where you got this gif?

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

                    http://fc00.deviantart.net/fs71/f/2012/189/a/a/dressage_horse_animation_by_lauwiie1993-d56it04.gif

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

                      I also tried this one: http://bestanimations.com/Animals/Mammals/Horses/horse-walking-animated-gif1.gif

                      Very simple, trotting horses. Not much memory space.

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

                        Downloaded it, then imported in Pythonista (+, import photo, no need to use a Photos script ) and quick look shows the movement.

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

                          1: Thanks for that, @cvp. I didn't even know that was there. How stupid of me; I have used Pythonista for several years now, and have never used anything in that menu except for add script, pyui file, and txt file.

                          2: It returns an IOError when I try to make a SpriteNode out of it. What now?

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

                            Hold on, made some adjustments...
                            It now produces a still image with no animation as a SpriteNode.

                            cvp 1 Reply Last reply Reply Quote 0
                            • cvp
                              cvp @NoBetterName last edited by

                              @NoBetterName Sorry, I've never used scene....I can't help you more.

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

                                @JonB Missing import.os and w.present

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

                                  @NoBetterName Since we don't have either your code, or a full traceback, how can we possibly help debug your code! Paste a minimal example that shows the issue, (using three backticks to format code), and paste a full traceback.

                                  Are you using the GifSpriteNode git?

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

                                    Oh, sorry about that. Right now, I'm just trying to fix a simplified, very basic, gif-SpriteNode thing-a-ma-bobby. This is my code:

                                    from scene import *
                                    
                                    class MyScene(Scene):
                                    	def setup(self):
                                    		img = 'horsegif.GIF'
                                    		texture = Texture(img)
                                    		background = SpriteNode(texture)
                                    		background.size = self.size
                                    		background.anchor_point = 0,0
                                    		background.position = 0,0
                                    		self.add_child(background)
                                    		
                                    run(MyScene())
                                    

                                    It isnt much.

                                    By that way, the adjustment that I made earlier was just making the Texture from a file path instead of a ui.Image of the gif file. I don't know why it changed the results... I'm a bit clueless when it comes to gifs.

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

                                      Perhaps, I say perhaps because I really don't know anything about scene, you could use image2gif to extract an array of PIL images (via readGif) and display each frame when scene runs....

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

                                        You could also extract frames of your gif online, by example here and download a zip with all the frames, and then process it locally

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

                                          Problem with that, scene runs 60 times per second. Way too fast. I used the example above to process a gif and add it to a scene. Thanks @ccc!
                                          I devised a switch system to slow down a gif if it goes too fast, as it seems that the gif @ccc referred to did something similar to your idea, @cvp. Thanks for all the help guys, and hopefully you will see this app on the App Store sometime soon!

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

                                            get_horse.py...

                                            import console, requests
                                            
                                            url = 'http://bestanimations.com/Animals/Mammals/Horses/horse-walking-animated-gif1.gif'
                                            # url = 'http://fc00.deviantart.net/fs71/f/2012/189/a/a/dressage_horse_animation_by_lauwiie1993-d56it04.gif'
                                            filename = url.split('/')[-1]
                                            
                                            with open(filename, 'wb') as out_file:
                                                out_file.write(requests.get(url).content)
                                            console.quicklook(filename)
                                            
                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors