Python快速分类横竖屏图片
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)
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 solitud.es
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果