Created
September 24, 2023 21:04
-
-
Save khengyun/f9fce201dfb13e676214fc3bf96216f9 to your computer and use it in GitHub Desktop.
convert all ppm file to image
This file contains 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_ppm_to_jpg(folder_path): | |
for root, dirs, files in os.walk(folder_path): | |
for filename in files: | |
if filename.endswith(".ppm"): | |
ppm_file_path = os.path.join(root, filename) | |
with Image.open(ppm_file_path) as img: | |
jpg_file_path = os.path.splitext(ppm_file_path)[0] + ".jpg" | |
img.save(jpg_file_path) | |
os.remove(ppm_file_path) | |
convert_ppm_to_jpg(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