Created
June 5, 2024 01:08
-
-
Save Marcellofabrizio/477d4aa54cd8d81a8eda5ed37dd3aca4 to your computer and use it in GitHub Desktop.
Convert to PNG
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
from PIL import Image | |
import sys | |
import os | |
def convert_jpeg_to_png(input_directory, output_directory): | |
if not os.path.exists(output_directory): | |
os.makedirs(output_directory) | |
for filename in os.listdir(input_directory): | |
if filename.lower().endswith(('.jpg', '.jpeg')): | |
input_path = os.path.join(input_directory, filename) | |
output_path = os.path.join(output_directory, os.path.splitext(filename)[0] + '.png') | |
with Image.open(input_path) as img: | |
img.save(output_path, 'PNG') | |
input_directory = sys.argv[1] | |
output_directory = sys.argv[2] | |
convert_jpeg_to_png(input_directory, output_directory) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment