[英]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.