如何在python中压缩图像文件?

时间:2016-03-29 11:45:08

标签: python optimization compression python-imaging-library

我正在处理文件传输项目,我希望以压缩格式下载从服务器下载的图像。我如何使用python做到这一点? 我想使用PIL模块来减小用户下载的每个图像的大小。

1 个答案:

答案 0 :(得分:0)

此函数将获取ur文件的输入路径,并将输出作为所有图像的zip文件输出到taht路径

 def zipper(path):
        """
        This function archives the output folder for more than one image files
        """
        # check if more than one files are there in output path
        total_image_files = os.listdir(path)
        zip_file = path +"/img.zip"
        zf = zipfile.ZipFile(zip_file, mode='w')
        for fe in total_image_files:
            zf.write(path + "/" + fe, arcname = fe)
        zf.close()
        return zip_file