2024年4月11日星期四

[Python]JPG to PNG Python Program

from PIL import Image import os def convert_jpg_to_png(input_folder, output_folder): # 1. Get list up the input folder files jpg_files = [f for f in os.listdir(input_folder) if f.endswith('.jpg')] # 2. Create the output folder if it did not exist os.makedirs(output_folder, exist_ok=True) # 3. Change the JPG to PNG files for jpg_file in jpg_files: jpg_path = os.path.join(input_folder, jpg_file) # Create the PNG file output path png_path = os.path.join(output_folder, os.path.splitext(jpg_file)[0] + '.png') # Change the image img = Image.open(jpg_path) img.save(png_path, 'PNG') if __name__ == "__main__": input_folder = "path" # Define the input path of JPG output_folder = "path" # Define the output path of PNG convert_jpg_to_png(input_folder, output_folder)

Need to get them work on my site...

没有评论:

发表评论