![](/img/trans.png)
[英]Python image library (PIL), how to compress image into desired file size?
[英]How to compress image file in python?
我正在处理一个文件传输项目,我希望从服务器下载的图像以压缩形式下载。 我如何使用 python 做到这一点? 我想使用 PIL 模块来减小用户下载的每个图像的大小。
此函数将采用 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.