在 python 中放大动画 GIF 以与 PyGTK 一起使用 [英] Scaling up an animated GIF in python to be used with PyGTK

查看:33
本文介绍了在 python 中放大动画 GIF 以与 PyGTK 一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个小的 python 脚本,它打开一个窗口并在窗口内放置一个动画 GIF.我将它用作屏幕保护程序(没什么特别的,真的).我的问题是 GIF 不是我显示器的大小;它在屏幕上很小.我想做的是将其缩放到屏幕的大小.我已经研究过 PIL 和 images2gif,但它们没有提供我需要的缩放选项.

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.

我想做的是在脚本中加载动画GIF,然后缩放它,最后在PyGTK生成的窗口中播放.我尝试做的是使用 subprocess 来捕获 gifsicle 的输出.虽然这确实缩放了 GIF,但由于从 subprocess 返回的数据,我无法在脚本的 PyGTK 部分使用它.我要做的是:

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)

变量 p 具有动画 GIF 数据,但在这种情况下我无法与 PyGTK 一起使用.理想情况下,我想像这样加载它:

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)

有没有办法让我使用 gifsicle --scale 3.3 foo.gif 调用中的数据?或者是否有一种纯 Python 方式来缩放动画 GIF 并将其与 PyGTK 一起使用?

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?

推荐答案

逻辑上你可以使用

GdkPixbuf.Pixbuf.scale_simple ()

在 GdkPixbuf.PixbufAnimation 中包含的所有 GdkPixbuf.如何获得单个GdkPixbuf.Pixbuf?使用 iter 遍历 GdkPixbuf.PixbufAnimation.第一个迭代将是

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

这篇关于在 python 中放大动画 GIF 以与 PyGTK 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆