jpeg_dir = "path/to/jpeg/directory"
png_dir = "path/to/png/directory"
# Loop through all the JPEG images in the directory
for filename in os.listdir(jpeg_dir):
if filename.endswith(".jpg") or filename.endswith(".jpeg"):
# Open the JPEG image using PIL
with Image.open(os.path.join(jpeg_dir, filename)) as im:
# Create a new filename for the PNG image
png_filename = os.path.splitext(filename)[0] + ".png"
# Save the image as a PNG in the new directory
im.save(os.path.join(png_dir, png_filename))