Last active
December 13, 2024 05:09
-
-
Save OlegKorn/5e53d37be8f0082be8413a6209b69233 to your computer and use it in GitHub Desktop.
python - convert webp to png
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
import os | |
import fnmatch | |
drives = ['G:\\'] | |
THIS_SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)).replace('\\', '/') | |
def convert_webp_to_png(webp_file_path): | |
with Image.open(webp_file_path).convert('RGB') as img: | |
new_png_name = webp_file_path.replace('webp', 'png') | |
img.save(new_png_name) | |
os.remove(webp_file_path) | |
print(f'Converted: {webp_file_path}') | |
def convert_all_webp_of_harddrive_to_png(): | |
for d in drives: | |
print("Now searching in ", d) | |
for (root, dirs, files) in os.walk(d): | |
for name in files: | |
if name.endswith('.webp'): | |
webp_file_path = os.path.join(root, name) | |
convert_webp_to_png(webp_file_path) | |
def convert_webp_to_png_in_a_dir(_dir): | |
for file in os.listdir(_dir): | |
if file.endswith(".webp"): | |
webp_file_path = os.path.join(_dir, file).replace('\\', '/') | |
convert_webp_to_png(webp_file_path) | |
convert_all_webp_of_harddrive_to_png() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment