小编Col*_*ain的帖子

如何循环两次 zip() 函数的一个元素 - Python

所以这是我的困境......我正在编写一个脚本,它从一个文件夹中读取所有 .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 …
Run Code Online (Sandbox Code Playgroud)

python zip loops resize image

5
推荐指数
1
解决办法
802
查看次数

标签 统计

image ×1

loops ×1

python ×1

resize ×1

zip ×1