简体   繁体   English

枕头 - 无法保存调整大小/裁剪的 gif

[英]Pillow - cannot save resized/cropped gif

I am using the Pillow package to change some gifs to animated.webp's with a square size.我正在使用Pillow package 将一些 gif 图像更改为正方形大小的 animated.webp。
The issue is that the saved file isn't resized/cropped.问题是保存的文件未调整大小/裁剪。
This is my code:这是我的代码:

destination = Path(source).with_suffix(".webp")
extension = ".webp"
        
im = Image.open(source)
width, height = im.size
          
if width != height:
  if width > height:
    left = (width - height)/2
    top = 0
    right = (width + height)/2
    bottom = height
  else:
    left = 0
    top = (height - width)/2
    right = width
    bottom = (height + width)/2

  if getattr(im, "is_animated", False):
    frames = ImageSequence.Iterator(im)
    cropped_frames = []
  
    for frame in frames:
      cropped_frames.append(frame.crop((left, top, right, bottom))) 

    im.save(destination, format="webp", save_all=True, optimize=True, append_images=list(frames), loop=0)

I believe you want to do this?我相信你想这样做?

save cropped_frames not frames保存cropped_frames而不是frames

im.save(destination, format="webp", save_all=True, optimize=True, append_images=cropped_frames, loop=0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM