【问题标题】:How to compress image file in python?如何在python中压缩图像文件?
【发布时间】:2016-03-30 12:10:31
【问题描述】:

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

【问题讨论】:

  • 您的问题目前非常模糊。请添加一些细节。为什么不能只提供具有自己压缩的图像,例如 PNG 格式?

标签: python optimization compression python-imaging-library


【解决方案1】:

此函数将获取您文件的输入路径,并将所有图像的 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-28
    • 2020-06-22
    • 2022-10-25
    • 2020-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多