2013-04-29 115 views
5

我有一個尺寸的圖像(288,352)。我想調整它到(160,240)。 我嘗試下面的代碼:在Python中調整圖像大小

im = imread('abc.png') 
img = im.resize((160, 240), Image.ANTIALIAS) 

但它給出了一個錯誤TypeError: an integer is required 請告訴我這樣做的最佳方式。

回答

7

matplotlib.pyplot.imread(或scipy.ndimage.imread)返回一個NumPy數組,而不是一個PIL圖像。

而是嘗試:

In [25]: import Image 
In [26]: img = Image.open(FILENAME) 
In [32]: img.size 
Out[32]: (250, 250) 

In [27]: img = img.resize((160, 240), Image.ANTIALIAS) 

In [28]: img.size 
Out[28]: (160, 240) 
+0

謝謝,這是工作:) – Khushboo 2013-04-29 12:20:28