I have this little python script which opens up a window and puts an animated GIF inside the window. I'm using it as a screensaver (nothing fancy, really). My problem is that the GIF isn't the size of my monitor; it's quite small on the screen. What I'd like to do is to scale it to the size of the screen. I have looked into PIL as well as images2gif, but they don't give me the scaling options I require.
What I would like to do is load the animated GIF in the script, then scale it, and finally play in the window generated by PyGTK. What I've tried doing is using subprocess
to capture the output from gifsicle. While this does scale the GIF I can't use it in the PyGTK part of the script because of the data returned from subprocess
. What I do is:
p = subprocess.check_output(["gifsicle --scale 3.3 foo.gif"], shell=True)
The variable p
has the animated GIF data, but I can't use with PyGTK in that condition. Ideally I would like to load it like this:
pixbufAn = gtk.gdk.pixbufAnimation(p)
image = gtk.Image()
image.set_from_animation(pixbufAn)
Is there a way for me to use the data from the gifsicle --scale 3.3 foo.gif
call? Or is there a pure Python way of scaling the animated GIF and using it with PyGTK?
logically you can use
GdkPixbuf.Pixbuf.scale_simple ()
on all the GdkPixbuf contains within GdkPixbuf.PixbufAnimation. How to get the single GdkPixbuf.Pixbuf? Use the iter to walk through GdkPixbuf.PixbufAnimation. first iter would be
iter = GdkPixbuf.PixbufAnimation.get_iter (GLib.get_current_time() )
pbuf = iter.get_pixbuf ()
# scale the pbuf below
......
# make this on a loop
iter = iter.advance (GLib.get_current_time())
# after getting all the pbuf, pack again into GdkPixbuf.PixbufSimpleAnim
simpleanim = GdkPixbuf.PixbufSimpleAnim (width, height, rate)
# loop again
simpleanim.add_frame (pbuf)
# after done all the chores, call the
Gtk.Image.set_from_animation (simpleanim) #simpleanim implemented anim