2016-03-29 29 views
-1

我正在處理文件傳輸項目,我希望從服務器下載的圖像以壓縮格式下載。我如何使用python做到這一點? 我想使用PIL模塊來減小用戶下載的每個圖像的大小。如何在python中壓縮圖像文件?

+0

你的問題是目前非常模糊。請添加一些細節。爲什麼你不能只提供具有自己壓縮的圖像,例如PNG格式? –

回答

0

此功能需要烏爾文件的輸入路徑,並給予輸出的所有圖像的壓縮文件到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