Khushboo
Khushboo

Reputation: 1718

Resizing an image in python

I have an image of size (288, 352). I want to resize it to (160, 240). I tried the following code:

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

But it gives an error TypeError: an integer is required Please tell me the best way to do it.

Upvotes: 13

Views: 38283

Answers (1)

unutbu
unutbu

Reputation: 879103

matplotlib.pyplot.imread (or scipy.ndimage.imread) returns a NumPy array, not a PIL Image.

Instead try:

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)

Upvotes: 17

Related Questions