哇塞,好羡慕哪些会写的大佬
{:10_279:}
本帖最后由 元豪 于 2023-5-1 08:35 编辑
import tinify, os, sys
tinify.key = 'key'
houzhui = ['.jpg', '.png', '.webp']
num = 0
s = t1 = t2 = None
ss = []
def printf(ttt):
def func():
ttt(s, t1, t2)
return func
@printf
def ttt(s, t1, t2):
print('({}/{})图片<{}>正在压缩处理中, 请稍后...'.format(t2, t1, s))
kkk = sys.argv
if len(kkk) > 1:
for i in kkk:
if os.path.splitext(i) in houzhui:
img = tinify.from_file('{}{}'.format(os.path.splitext(i), os.path.splitext(i)))
img.to_file('{}{}'.format(os.path.splitext(i) + '_new', os.path.splitext(i)))
num += 1
ss.append(os.path.splitext(i) + os.path.splitext(i))
t1 = num
for i in range(num):
t2 = i + 1
s = ss
ttt()
else:
x = input('请输入需要压缩的图片(回车优化当前文件夹): ')
if not x:
print('开始优化当前文件下所有.jpg/.png/.webp文件')
g = input('请输入尺寸(宽度 高度): ')
if not g:
for i in os.listdir('./'):
hou = os.path.splitext(i)
if hou in houzhui:
img = tinify.from_file('{}{}'.format(os.path.splitext(i), os.path.splitext(i)))
img.to_file('{}{}'.format('new_' + os.path.splitext(i), os.path.splitext(i)))
ss.append(os.path.splitext(i) + os.path.splitext(i))
num += 1
t1 = num
for i in range(num):
s = ss
t2 = i + 1
ttt()
elif '0' in g.split():
w, h = map(int, g.split())
for i in os.listdir('./'):
hou = os.path.splitext(i)
if hou in houzhui:
img = tinify.from_file('{}{}'.format(os.path.splitext(i), os.path.splitext(i)))
if w == 0:
newimg = img.resize(method='scale', height=h)
else:
newimg = img.resize(method='scale', width=w)
newimg.to_file('{}{}'.format('new_' + os.path.splitext(i), os.path.splitext(i)))
ss.append(os.path.splitext(i) + os.path.splitext(i))
num += 1
t1 = num
for i in range(num):
s = ss
t2 = i + 1
ttt()
else:
w, h = map(int, g.split())
for i in os.listdir('./'):
hou = os.path.splitext(i)
if hou in houzhui:
img = tinify.from_file('{}{}'.format(os.path.splitext(i), os.path.splitext(i)))
newimg = img.resize(method='fit', width=w, height=h)
newimg.to_file('{}{}'.format('new_' + os.path.splitext(i), os.path.splitext(i)))
ss.append(os.path.splitext(i) + os.path.splitext(i))
num += 1
t1 = num
for i in range(num):
s = ss
t2 = i + 1
ttt()
else:
g = input('请输入尺寸(宽度 高度): ')
if not g:
img = tinify.from_file('{}{}'.format(os.path.splitext(x), os.path.splitext(x)))
img.to_file('{}{}'.format('new_' + os.path.splitext(x), os.path.splitext(x)))
s = '{}{}'.format(os.path.splitext(x), os.path.splitext(x))
t1 = t2 = 1
ttt()
else:
w, h = map(int, g.split())
img = tinify.from_file('{}{}'.format(os.path.splitext(x), os.path.splitext(x)))
if w and h:
newimg = img.resize(method='fit', width=w, height=h)
elif not w:
newimg = img.resize(method='scale', height=h)
elif not h:
newimg = img.resize(method='scale', width=w)
newimg.to_file('new_{}{}'.format(os.path.splitext(x), os.path.splitext(x)))
s = '{}{}'.format(os.path.splitext(x), os.path.splitext(x))
t1 = 1
t2 = 1
ttt()
print('全部处理完成~')
@小甲鱼 可以把最后一个名额给我吗{:10_254:}写了好久
元豪 发表于 2023-5-1 07:50
@小甲鱼 可以把最后一个名额给我吗写了好久
这个帖子的活动过期很久啦~
不过此时此刻这里有一个活动正在进行 -> https://fishc.com.cn/thread-226860-1-1.html
快冲!!
小甲鱼 发表于 2023-5-2 02:36
这个帖子的活动过期很久啦~
不过此时此刻这里有一个活动正在进行 -> https://fishc.com.cn/thread-226 ...
那我可以要少点 , 我是真的想要{:10_254:}
朕想知道
1
1
1
哇!塞,好羡慕哪些会写的大佬
本帖最后由 C1em 于 2023-8-9 21:04 编辑
新的一周继续加油
好高级呀,需要仔细研究研究。
6666
本帖最后由 clollipops 于 2023-7-25 18:27 编辑
火爆全球的主流图片压缩方案自动化脚本
666,感谢分享,收藏了好好研究研究~
这个值得收藏,反复观看
666慢慢学
打卡,目前我的实力还不允许我写出来呢{:5_90:}
see
朕想知道