from PIL import Image
import os
import concurrent.futures

input_dir = "D:\\Download\\webpic-part1\\20211201"
output_dir = "D:\\Download"
horizontal_dir = os.path.join(output_dir, "horizontal")
vertical_dir = os.path.join(output_dir, "vertical")
os.makedirs(horizontal_dir, exist_ok=True)
os.makedirs(vertical_dir, exist_ok=True)

def process_image(filename):
    file_path = os.path.join(input_dir, filename)
    with Image.open(file_path) as image:
        width, height = image.size
        if width > height:
            image.save(os.path.join(horizontal_dir, filename))
        else:
            image.save(os.path.join(vertical_dir, filename))
    print("Processed:", filename)

image_filenames = os.listdir(input_dir)
with concurrent.futures.ThreadPoolExecutor(max_workers=12) as executor:
    executor.map(process_image, image_filenames)