Last active
May 11, 2025 14:15
-
-
Save khengyun/92d321b301df4ddc60c7bc7b6dbbce42 to your computer and use it in GitHub Desktop.
convert all image in a folder to ppm format
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
import os | |
from PIL import Image | |
root_folder = "folder_path" | |
def convert_image_to_ppm(folder_path): | |
for root, dirs, files in os.walk(folder_path): | |
for filename in files: | |
if filename.endswith((".png", ".jpg")): | |
image_file_path = os.path.join(root, filename) | |
with Image.open(image_file_path) as img: | |
ppm_file_path = os.path.splitext(image_file_path)[0] + ".ppm" | |
img.save(ppm_file_path) | |
os.remove(image_file_path) | |
convert_image_to_ppm(root_folder) | |
print("Conversion and replacement complete.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment