Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

脚本里每次压缩图片调用了两次压缩接口方法 #2

Open
xrksudy opened this issue Oct 9, 2016 · 1 comment
Open

脚本里每次压缩图片调用了两次压缩接口方法 #2

xrksudy opened this issue Oct 9, 2016 · 1 comment

Comments

@xrksudy
Copy link

xrksudy commented Oct 9, 2016

参考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()

@saitjr
Copy link
Owner

saitjr commented Oct 9, 2016

好的,我改改,谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants