Skip to content

Instantly share code, notes, and snippets.

@ProGamerGov
Created February 12, 2023 21:09
Show Gist options
  • Save ProGamerGov/c49d872b86fffd37be9f1fd118d89f97 to your computer and use it in GitHub Desktop.
Save ProGamerGov/c49d872b86fffd37be9f1fd118d89f97 to your computer and use it in GitHub Desktop.

Revisions

  1. ProGamerGov created this gist Feb 12, 2023.
    16 changes: 16 additions & 0 deletions convert_webp_to_png.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    import os
    from PIL import Image

    def convert_webp_to_png(directory: str, delete_old_webp_images: bool = False):
    for root, dirs, files in os.walk(directory):
    for file in files:
    if file.endswith(".webp"):
    filepath = os.path.join(root, file)
    img = Image.open(filepath)
    new_filepath = os.path.splitext(filepath)[0] + ".png"
    img.save(new_filepath, "png", quality=100)
    if delete_old_webp_images:
    os.remove(filepath)


    convert_webp_to_png("/path/to/directory")