from PIL import Image import os import pprint # Set the folder containing images folder_path = 'converted' # Replace with your folder path output_folder = os.path.join(folder_path, 'dingus') # Create the 'dingus' folder if it doesn't exist if not os.path.exists(output_folder): os.makedirs(output_folder) # Initialize a pretty printer pp = pprint.PrettyPrinter(indent=4) # Iterate through all files in the folder for filename in os.listdir(folder_path): if filename.endswith(('.png', '.jpg', '.jpeg', '.bmp', '.tiff')): # Add more formats if needed file_path = os.path.join(folder_path, filename) # Open the image try: with Image.open(file_path) as img: # Ensure the image is in 'RGBA' mode (32-bit with 4 channels: R, G, B, A) img = img.convert('RGBA') # Create the save path as a PNG in the 'dingus' folder save_path = os.path.join(output_folder, f'{os.path.splitext(filename)[0]}.png') # Save the image as PNG img.save(save_path, 'PNG') # Pretty-print the successful conversion pp.pprint(f"Successfully converted and saved: {save_path}") except Exception as e: pp.pprint(f"Error processing {filename}: {e}") print("Conversion complete!")