https://www.webucator.com/tutorial/using-python-to-convert-images-to-webp/
from pathlib import Path
from PIL import Image
def convert_to_webp(source):
"""Convert image to webp.
Args:
source (pathlib.Path): Path to source image
Returns:
pathlib.Path: path to new image
"""
destination = source.with_suffix(".webp")
image = Image.open(source) # Open image
image.save(destination, format="webp") # Convert image to webp
return destination
def main():
paths = Path("pic").glob("**/*.jpg")
for path in paths:
webp_path = convert_to_webp(path)
print(webp_path)
main()
本文作者:TwinIsland
本文链接:erdao.me/nichijou/133.html
版权声明:所有文章除特别声明外均系本人自主创作,转载及引用请注明出处