我尝试过两种方法:
将PIL.Images列表保存为webp文件:
from PIL import Image
import os
frames = []
fdir = "./frames"
for f in sorted(os.listdir(fdir)):
f = os.path.join(fdir, f)
frames.append(Image.open(f))
frames = frames[:100]
frames[0].save("./test.webp", "webp", save_all=True, append
我正在尝试使用PIL/Pillow将一些.png文件转换为gif。以下脚本正在工作,但正在以随机顺序添加帧。
from PIL import Image
import glob
# Create frames
frames = []
imgs = glob.glob("*.png")
for i in imgs:
new_frame = Image.open(i)
frames.append(new_frame)
# Save into a GIF file that loops forever
frames[0].save('globe.gif
我用枕头做GIF。我的输出结果是这样的,以前的图像是绑定的,因为透明性。
我的代码是:
import shutil
from PIL import Image
from .helpers import *
def animate(anifile=None, width=None, height=None, loop=None, bonds_param=None):
if width is None:
width = 1920
if height is None:
height = 1080
if loop is None:
Problem:当将Image序列保存为具有透明性的gif时,它工作得很好,但是当保存为webp时,透明度在所有帧中都会丢失。
使用:Python (最新)与PIL (最新)
问题:如何解决这一问题,以及是什么原因造成的?
代码:
from PIL import Image, ImageSequence
def gen_frame(im: Image) -> Image:
alpha = im.getchannel('A')
# Convert the image into P mode but only use 255 colors in the p
我试图将具有透明背景的PNG图像列表转换为GIF,同时保持背景透明性。我使用了我找到的这段代码,并对其进行了修改:
import os
from PIL import Image
# Create the frames
frames = []
path = "directory/to/my/png/images"
for frame in os.listdir(path):
new_frame = Image.open(path + "/" + frame)
frames.append(new_frame)
# Save into a GI
我使用python枕头做一个简单的gif图像反转,但我发现图像比以前(1M)更大(10米)。有人知道怎么做吗?这是我的密码:
from PIL import Image, ImageSequence
from PIL import ImagePalette
with Image.open('sd.gif') as im:
if im.is_animated:
frames = [f.copy() for f in ImageSequence.Iterator(im)]
frames.reverse()
frames[0].