import os from PIL import Image, ImageDraw # Specify the path to the input folder input_folder = 'input_images' output_folder = 'output_images' # Create the output folder if it does not exist if not os.path.exists(output_folder): os.makedirs(output_folder) # Process all JPG files in the folder for filename in os.listdir(input_folder): if filename.lower().endswith('.jpg'): image_path = os.path.join(input_folder, filename) image = Image.open(image_path).convert("RGBA") # Create a drawing context draw = ImageDraw.Draw(image) # Define the points for the top-left and top-right triangles tri = 125 top_left_triangle = [(0, 0), (tri, 0), (0, tri)] top_right_triangle = [(512-tri, 0), (512, 0), (512, tri)] # Draw the triangles with transparent fill draw.polygon(top_left_triangle, fill=(0, 0, 0, 0)) draw.polygon(top_right_triangle, fill=(0, 0, 0, 0)) # Save the modified image with a changed file name and PNG format output_filename = os.path.splitext(filename)[0] + '.png' output_path = os.path.join(output_folder, output_filename) image.save(output_path) print("All images have been processed.")