Skip to content

Instantly share code, notes, and snippets.

@Marcellofabrizio
Created June 5, 2024 01:08
Show Gist options
  • Save Marcellofabrizio/477d4aa54cd8d81a8eda5ed37dd3aca4 to your computer and use it in GitHub Desktop.
Save Marcellofabrizio/477d4aa54cd8d81a8eda5ed37dd3aca4 to your computer and use it in GitHub Desktop.
Convert to PNG
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