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
-
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?
-
-
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?
-
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.
-
No, I tried downloading it in two ways...
- Copy the image. Use the clipboard module to save the copied file. It displays the gif animation on Safari, but not in Pythonista.
- 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.
-
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.
-
Is it possible to post here the URL where you got this gif?
-
-
I also tried this one: http://bestanimations.com/Animals/Mammals/Horses/horse-walking-animated-gif1.gif
Very simple, trotting horses. Not much memory space.
-
Downloaded it, then imported in Pythonista (+, import photo, no need to use a Photos script ) and quick look shows the movement.
-
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?
-
Hold on, made some adjustments...
It now produces a still image with no animation as a SpriteNode. -
@NoBetterName Sorry, I've never used scene....I can't help you more.
-
@JonB Missing import.os and w.present
-
@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?
-
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.
-
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....
-
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
-
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! -
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)