如果您想以编程方式执行此操作(我认为是这种情况),请使用 PIL 来调整大小,例如
newIm = im.resize((newW, newH)
然后将其保存到同一文件或新位置。
递归地遍历文件夹并对所有图像应用调整大小功能。
我想出了一个示例脚本,我认为它适合您。您可以对其进行改进:也许将其图形化,添加更多选项,例如相同的扩展名或可能都是 png,调整采样线性/双线性等大小
import os
import sys
from PIL import Image
def resize(folder, fileName, factor):
filePath = os.path.join(folder, fileName)
im = Image.open(filePath)
w, h = im.size
newIm = im.resize((int(w*factor), int(h*factor)))
# i am saving a copy, you can overrider orginal, or save to other folder
newIm.save(filePath+"copy.png")
def bulkResize(imageFolder, factor):
imgExts = ["png", "bmp", "jpg"]
for path, dirs, files in os.walk(imageFolder):
for fileName in files:
ext = fileName[-3:].lower()
if ext not in imgExts:
continue
resize(path, fileName, factor)
if __name__ == "__main__":
imageFolder=sys.argv[1] # first arg is path to image folder
resizeFactor=float(sys.argv[2])/100.0# 2nd is resize in %
bulkResize(imageFolder, resizeFactor)