python双循环zip_如何在zip()函数的一个元素中循环两次Python

这是我的dilema。。。我正在编写一个脚本,从一个文件夹中读取所有的.png文件,然后将它们转换成我在列表中指定的许多不同维度。除了在处理一个图像后退出之外,一切都正常工作。在

这是我的代码:sizeFormats = ["1024x1024", "114x114", "40x40", "58x58", "60x60", "640x1136", "640x960"]

def resizeImages():

widthList = []

heightList = []

resizedHeight = 0

resizedWidth = 0

#targetPath is the path to the folder that contains the images

folderToResizeContents = os.listdir(targetPath)

#This splits the dimensions into 2 separate lists for height and width (ex: 640x960 adds

#640 to widthList and 960 to heightList

for index in sizeFormats:

widthList.append(index.split("x")[0])

heightList.append(index.split("x")[1])

#for every image in the folder, apply the dimensions from the populated lists and save

for image,w,h in zip(folderToResizeContents,widthList,heightList):

resizedWidth = int(w)

resizedHeight = int(h)

sourceFilePath = os.path.join(targetPath,image)

imageFileToConvert = Image.open(sourceFilePath)

outputFile = imageFileToConvert.resize((resizedWidth,resizedHeight), Image.ANTIALIAS)

outputFile.save(sourceFilePath)

如果目标文件夹包含两个名为image1.png、image2.png的图像,则将返回以下内容(为了可视化起见,我将在下划线后添加应用于图像的维度):

图像1_1024x1024.png,

..............,

image1_640x690.png(返回image1 fine的所有7个不同维度)

当我需要它对图像2应用相同的变换时,它就停止了。我知道这是因为widthList和heightList的长度只有7个元素,所以在image2轮到它之前就退出了循环。有什么方法可以让我循环遍历targetPath中每个图像的widthList和heightList吗?在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值