PNG、 JPG图片压缩方法

参考链接 https://tinypng.com/developers/reference/python

1、安装

pip install --upgrade tinify

2、使用python脚本压缩图片

import tinify
tinify.key = "YOUR_API_KEY"
source = tinify.from_file("unoptimized.jpg")
source.to_file("optimized.jpg")

3、注册获取key

https://tinypng.com/developers

每个月有500张免费使用

4、例如:

import tinify
import os
import sys
# user lipeilong@joyodream.com rigister key
tinify.key = "Ly9VUp8wM1v9jBdThRgvyfRhll0QeW7X"
if len(sys.argv) >= :
srcPath = sys.argv[]
dstPath = sys.argv[]
else:
srcPath = "./src"
dstPath = "./dst" for (path, dirs, files) in os.walk(srcPath):
for filename in files:
srcName = srcPath + "/" + filename
dstName = dstPath + "/" + filename
source = tinify.from_file(srcName)
source.to_file(dstName)
上一篇:python代码检索小引擎


下一篇:React Native原生模块向JS传递数据的几种方式(Android)