[Tutor] Resizing .gif images with resize() from PIL

Walter Vannini walterv@jps.net
Thu, 10 May 2001 15:47:14 -0700


There are two major problems with the use of resize here.
The first is that the size (900 by 412 in this example)
has to passed in as a single variable (for example, as a tuple
like (900,412) ).
The second is that the return value has to be used
for saving.
The original image object is not changed. Instead, a new image
object that is a resized version of the original is returned.

The code snippet
 im.resize(900, 412)
 im.save("\windows\desktop\jah_wobble.gif", "GIF")

should be changed to something like
 newim = im.resize( (900,412) )
 newim.save(r"\windows\desktop\jah_wobble.gif", "GIF")

Walter.

> I am getting some rather confusing output from PIL. It does an excellent job
> of converting one format to another(in this case BMP to GIF). However
> resizing has been problematic for me.
> 
> when I attempt
> 
> import Image
> # import os, sys
> im=Image.open("\windows\desktop\johnny_rotten.bmp")
> #image starts out at 1449, 961. Too big!
> im.resize(900, 412)
> im.save("\windows\desktop\jah_wobble.gif", "GIF")
> 
> I get
> 
> Traceback (most recent call last):
>   File "flip-flop-testing.py", line 4, in ?
>     im.resize(900, 412)
>   File "c:python20pilImage.py", line 632, in resize
>     raise ValueError, "unknown resampling filter"
> ValueError: unknown resampling filter
> 
> Which error I have searched for to no avail.
...
> why is resize croaking? I must admit
> confusion.