Python knowledge points 100 articles series (10) - two ways to use python to compress pictures

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

Guess you like

Origin blog.csdn.net/weixin_42551921/article/details/127912908