原来是png图片,用这个代码压缩不了。要用这个代码,可能压缩:
首先,安装epel-release仓库:
sudo yum install epel-release
然后,安装pngquant工具:
sudo yum install pngquant
安装完成后,你可以使用以下修改后的代码来压缩PNG格式的图片:
import os
from PIL import Image
def compress_image(input_path):
if os.path.getsize(input_path) <= 300*1024:
return None
else:
if input_path.lower().endswith('.png'):
os.system(f'pngquant {input_path} --output {input_path}')
print(input_path, "PNG图片压缩完成")
【 在 feng321 的大作中提到: 】
: [code=py]
: import os
: from PIL import Image
: ...................
--
FROM 120.242.240.*