简体   繁体   English

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

[英]How to compress image file in python?

I am working on a file transfer project and I want the images downloaded from the server to be downloaded in the compressed form.我正在处理一个文件传输项目,我希望从服务器下载的图像以压缩形式下载。 How do I do it using python?我如何使用 python 做到这一点? I want to use PIL Module to reduce the size of every image that the user downloads.我想使用 PIL 模块来减小用户下载的每个图像的大小。

This function will take input path of ur file and give output as zip file of all images to taht path此函数将采用 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM