相关疑难解决方法(0)

PIL - 将GIF帧转换为JPG

我尝试使用Python图像库将gif转换为单个图像,但它会导致奇怪的帧

输入gif是:

来源图片http://longcat.de/gif_example.gif

在我的第一次尝试中,我尝试将Image.new图像转换为RGB图像,其中255,255,255为白色背景 - 就像我在互联网上找到的任何其他示例一样:

def processImage( infile ):

    try:
        im = Image.open( infile )
    except IOError:
        print "Cant load", infile
        sys.exit(1)

    i = 0

    try:
        while 1:

            background = Image.new("RGB", im.size, (255, 255, 255))
            background.paste(im)
            background.save('foo'+str(i)+'.jpg', 'JPEG', quality=80)

            i += 1
            im.seek( im.tell() + 1 )

    except EOFError:
        pass # end of sequence
Run Code Online (Sandbox Code Playgroud)

但它导致奇怪的输出文件:

示例#1 http://longcat.de/gif_example1.jpg

我的第二次尝试是,首先在RGBA中转换gif,然后使用其透明蒙版,使透明片变白:

def processImage( infile ):

    try:
        im = Image.open( infile )
    except IOError:
        print "Cant load", infile
        sys.exit(1)

    i = 0

    try: …
Run Code Online (Sandbox Code Playgroud)

python jpeg image-processing gif python-imaging-library

16
推荐指数
1
解决办法
2万
查看次数

Python:将GIF帧转换为PNG

我是python的新手,试图用它将GIF的帧分割成PNG图像.

# Using this GIF: http://www.videogamesprites.net/FinalFantasy1/Party/Before/Fighter-Front.gif

from PIL import Image

im = Image.open('Fighter-Front.gif')
transparency = im.info['transparency'] 
im.save('test1.png', transparency=transparency)

im.seek(im.tell()+1)
transparency = im.info['transparency'] 
im.save('test2.png', transparency=transparency)

# First frame comes out perfect, second frame (test2.png) comes out black,
# but in the "right shape", i.e. 
# http://i.stack.imgur.com/5GvzC.png
Run Code Online (Sandbox Code Playgroud)

这是特定于我正在使用的图像还是我做错了什么?

谢谢!

python png animated-gif python-imaging-library

13
推荐指数
2
解决办法
1万
查看次数