Image.show deletes the image in a temporary file and then tries to display the file. It calls ImageShow.Viewer.show_image (see /usr/lib/python2.7/dist-packages/PIL/ImageShow.py ):
class Viewer: def save_image(self, image):
AFAIK, the standard PIL cannot save animated GIfs 1 .
The call to image._dump in Viewer.save_image saves only the first frame. Therefore, no matter which viewer is subsequently called up, you only see a static image.
If you have Imagemagick display , you should also have your animate program. Therefore, if you already have a GIF file, you can use
animate /path/to/animated.gif
To do this from Python, you can use the subprocess module (instead of img.show ):
import subprocess proc = subprocess.Popen(['animate', '/path/to/animated.gif']) proc.communicate()
1 According to kostmo , there is a script for saving animated GIFs with PIL.
To show animation without blocking the main process, use a separate thread to invoke the animate command:
import subprocess import threading def worker(): proc = subprocess.Popen(['animate', '/path/to/animated.gif']) proc.communicate() t = threading.Thread(target = worker) t.daemon = True t.start()
unutbu
source share