问题描述
我需要在 Python 中调整文件夹中的图像大小。通过使用下面的代码,我最终如何获得它们的相同维度?
from PIL import Image
import os
path = "E:/Jupyter-Project/images/test/car/"
resize_ratio = 0.5
def resize_aspect_fit():
dirs = os.listdir(path)
for item in dirs:
if item == '.jpg':
continue
if os.path.isfile(path+item):
image = Image.open(path+item)
file_path,extension = os.path.splitext(path+item)
new_image_height = int(image.size[0] / (1/resize_ratio))
new_image_length = int(image.size[1] / (1/resize_ratio))
image = image.resize((new_image_height,new_image_length),Image.ANTIALIAS)
image.save(file_path + "_small" + extension,'JPEG',quality=90)
resize_aspect_fit()
代码运行完美,但有些图像是 3K,其他是 4...我真的不知道如何修改它以达到相同的尺寸。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)