saitjr / STTinyPNG-Python

TinyPNG 批量压缩图片脚本
MIT License
61 stars 21 forks source link

脚本无法使用,可以参考以下方式修改 #3

Open gaojingwen945 opened 7 years ago

gaojingwen945 commented 7 years ago

使用原脚本时,总是提示目标文件夹中的某文件不存在,应该是source设置为了toFullName导致的。 可以改写为读写文件的方式,测试ok。 附参考链接:http://blog.csdn.net/jy692405180/article/details/52409369 修改后的脚本如下:

for root, dirs, files in os.walk(fromFilePath):
    for name in files:
    fileName, fileSuffix = os.path.splitext(name)
    if fileSuffix == '.png' or fileSuffix == '.jpg':
        toFullPath = toFilePath + root[len(fromFilePath):]
        toFullName = toFullPath + '/' + name
        fromFullPath = fromFilePath + root[len(fromFilePath):]
        fromFullName = fromFullPath + '/' + name

        if os.path.isdir(toFullPath):
            pass
        else:
            os.mkdir(toFullPath)

        source = tinify.from_file(fromFullName)
        source.to_file(toFullName)
saitjr commented 7 years ago

好的,谢谢

Aeiric commented 6 years ago

修改之后报错 IndentationError: unindent does not match any outer indentation level

Aeiric commented 6 years ago

额 无视上面那个问题 还是filenotfound