Python转换png到webp
直接上代码
1#!/usr/bin/python
2from pathlib import Path
3from PIL import Image
4
5def convert_to_webp(source):
6 destination = source.with_suffix(".webp")
7 image = Image.open(source)
8 image.save(destination, format="webp")
9 return destination
10
11def main():
12 paths = Path(".").glob("**/*.png")
13 for path in paths:
14 webp_path = convert_to_webp(path)
15 print(webp_path)
16
17main()