STTinyPNG-Python icon indicating copy to clipboard operation
STTinyPNG-Python copied to clipboard

TinyPNG 批量压缩图片脚本

Results 3 STTinyPNG-Python issues
Sort by recently updated
recently updated
newest added

使用原脚本时,总是提示目标文件夹中的某文件不存在,应该是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 +...

参考tinypng官方接口文档:https://tinypng.com/developers/reference/python 可以发现脚本中压缩统一张图片调用了2次接口,由于每个key每个月只能免费压缩500张,因此这种方式每压缩一张图片就浪费了一次机会。 ## 方式一 source = tinify.from_file(root + '/' + name) source.to_file(toFullName) ## 方式二 with open(toFullName, 'rb') as source: source_data = source.read() result_data = tinify.from_buffer(source_data).to_buffer()

chinese comments cause error when python STTinyPNG-Python.py