There are two cases of using python to compress image size:
- Reduce the size of the image while reducing the size of the image
- Do not change the size of the picture, reduce the quality of the picture, reduce the quality of the picture
In both cases the PIL module is used;
In the first case, use the resize method:
The pseudo code is as follows:
# 压缩图片文件
def compress_image(outfile, mb=150, k=0.9):
"""
:param outfile: 压缩文件保存地址
:param mb: 压缩目标,KB
:param k: 每次调整的压缩比率
:return: 压缩文件地址,压缩文件大小
"""
f