2013-03-24 53 views
1

我想導出使用下面的代碼給定的圖像大小的JPEG文件(省略下載的部分,因爲這工作正常):類型錯誤時,JPEG出口試圖

basewidth = 400 # user-defined variable 
wpercent = (basewidth/float(img.size[0])) 
hsize = int((float(img.size[1])*float(wpercent))) 
img = img.resize((basewidth,hsize), Image.ANTIALIAS) 
theitemishere = "/home/myusername/public_html/resizer/" + filename 
img.save(theitemishere + extension, extension_caps) 

但是,我得到的以下錯誤,當談到時間來保存新的圖像(這裏的回溯):

File "/home/myusername/public_html/cgi-bin/PIL/Image.py", line 1467, in save 
    save_handler(self, fp, filename) 
    File "/home/myusername/public_html/cgi-bin/PIL/JpegImagePlugin.py", line 557, in _save 
    ImageFile._save(im, fp, [("jpeg", (0,0)+im.size, 0, rawmode)]) 
    File "/home/myusername/public_html/cgi-bin/PIL/ImageFile.py", line 466, in _save 
    e = Image._getencoder(im.mode, e, a, im.encoderconfig) 
    File "/home/myusername/public_html/cgi-bin/PIL/Image.py", line 395, in _getencoder 
    return encoder(mode, *args + extra) 
TypeError: function takes at most 11 arguments (13 given) 

上爲什麼發生這種情況有什麼想法?

FWIW,我無法在服務器上安裝PIL模塊,這就是爲什麼我把它作爲cgi-bin的子目錄。

+0

完整的源代碼可以在[this gist]中找到(https://gist.github.com/anonymous/5234052) – tehsockz 2013-03-24 23:27:57

回答

7

我有同樣的問題,並解決它。寫這個解決方案,因爲我覺得上述答案不足以描述其他人有同樣的問題,並尋找解決方案

我有這個問題,因爲我有兩個PIL n枕頭安裝。所以不得不卸載其中之一。這解決了問題。

謝謝。

+0

我遇到了一個非常類似的問題,但不是卸載其中一個庫,而是更改了導入語句。看看我的問題和解決方案在http://stackoverflow.com/questions/17451711/typeerror-when-resizing-an-image-with-pil-in-python/17451810#17451810 – Caumons 2013-07-03 15:16:56

+1

是的...這也應該工作。 – 2013-07-03 17:09:47

1

你可能想跳過一切,並加載圖像開始,並立即將其保存:

img.save("/home/myusername/public_html/resizer/file.jpg", format="JPEG") 

,看看會發生什麼。如果它工作,然後添加更多的細節,調整大小和其他東西。

啊,不要忘記檢查你保存的文件夾的寫權限,因爲web服務器通常運行在不同的用戶名下。

+0

我得到了相同的基本錯誤:11個參數,給定13 ...雙重檢查權限 - 他們不是問題。實際上,文件本身被創建(儘管大小爲0字節)......所以看起來問題發生在正在保存的某個地方。思考? – tehsockz 2013-03-25 21:32:44

+0

我試圖在開發機器上安裝完全相同版本的PIL,但正確(不在cgi-bin)並檢查它是否運行良好。如果它有效,你需要重新安裝服務器上的東西,如果沒有,你需要一個不同版本的PIL。 – lenik 2013-03-25 22:01:29

+0

在開發機器上完美工作;看起來你是對的,因爲服務器上有一些奇怪的事情發生。 – tehsockz 2013-03-26 11:13:31