python Realization Method of Batch Modifying Picture Size and Saving Specified Path

  • 2021-07-09 08:48:20
  • OfStack

As shown below:


import os
from PIL import Image
 
filename = os.listdir("D:\\Work\\process\\ Sample processing \\polyu-all-train")
base_dir = "D:\\Work\\process\\ Sample processing \\polyu-all-train\\"
new_dir = "D:\\Work\\process\\ Sample processing \\polyu\\"
size_m = 128
size_n = 128
 
for img in filename:
  image = Image.open(base_dir + img)
  image_size = image.resize((size_m, size_n),Image.ANTIALIAS)
  image_size.save(new_dir+ img)

Related articles: