Spaces:
Sleeping
Sleeping
| from PIL import Image | |
| import os | |
| def convert_to_webp(input_file, output_file=None): | |
| try: | |
| img = Image.open(input_file) | |
| if output_file is None: | |
| base_name = os.path.splitext(input_file)[0] | |
| output_file = f"{base_name}.webp" | |
| img.save(output_file, "WEBP") | |
| print(f"saved as {output_file}") | |
| except Exception as e: | |
| print(f"error saving: {e}") | |
| def process_images_in_directory(directory): | |
| print(directory) | |
| for filename in os.listdir(directory): | |
| if filename.lower().endswith(('.jpg', '.png', '.jpeg')): | |
| input_path = os.path.join(directory, filename) | |
| convert_to_webp(input_path) | |
| if __name__ == "__main__": | |
| current_directory = os.getcwd() | |
| print(f"current_directory: {current_directory}") | |
| directory = "./examples/" | |
| process_images_in_directory(directory) |