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

kromag@nsacom.net kromag@nsacom.net
Thu, 10 May 2001 16:14:56 -0700 (PDT)


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.

When I try the thumbnail call:

import Image
# import os, sys
im=Image.open("\windows\desktop\johnny_rotten.bmp")
im.thumbnail(900, 412)
im.save("\windows\desktop\jah_wobble.gif", "GIF") 

Traceback (most recent call last):
  File "flip-flop-testing.py", line 4, in ?
    im.thumbnail(900, 412)
TypeError: too many arguments; expected 2, got 3

Yow! Back to the drawing board.

import Image
# import os, sys
im=Image.open("\windows\desktop\album.bmp")
im.thumbnail((900, 412))
im.save("\windows\desktop\anger_is_an_energy.gif", "GIF") 

Works, except the image is horribly blurry and blocky. It looks like 
something converted from JPG to GIF under an old version of photoshop! :-)

Is thumbnail for jpegs only? And why is resize croaking? I must admit 
confusion.

d