error module' object has no attribute 'LANCZOS
<p>I  want to resize an image to 28*28 pixel <code>.jpeg</code>. And I use the module called <code>PIL</code> for resize this picture :
I created this class :</p>

<pre><code>from PIL import Image

#import PIL
import numpy
from resizeimage import resizeimage

import scipy.misc

''' This class is to resize input image to MNIST size (28x28 px) '''


class Resize_img:
    def __init__(self, imageName):
        print 'Image -- ', imageName
        self.resized_image = ''
        # resize img to mnist size [28x28]
        #with open(imageName,'r+b') as f:
        #    with Image.open(f) as image:
    image = Image.open(imageName)        
        cover = resizeimage.resize_cover(image, [28, 28])
        self.resized_image = 'new ' + imageName
        cover.save(self.resized_image, image.format)
        # transform img to MNIST form
        # image to ndarray 
        PILimg = PIL.Image.open(self.resized_image)

        self.mnist_image_input = scipy.misc.fromimage(PILimg,
                                                      True)  # True =&gt; space gray! ----------------------------------------------------
        self.mnist_image_input = (numpy.multiply(self.mnist_image_input,
                                                 1.0 / 255.0) - 1.0) * -1.0  # inverse the image :D  ( white -&gt; dark )


def main():  # To test this Class.
    imageTest = '2.jpeg'  # The name of the image to resize

    imageTest = Resize_img(imageTest)
    scipy.misc.imshow(imageTest.mnist_image_input)


if __name__ == "__main__":
    main()


# sudo apt-get install libtiff4-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev python-tk
</code></pre>

<p>the error is : </p>

<pre><code>Image --  2.jpeg
Traceback (most recent call last):
  File "Resize_img.py", line 40, in &lt;module&gt;
    main()
  File "Resize_img.py", line 35, in main
    imageTest = Resize_img(imageTest)
  File "Resize_img.py", line 18, in __init__
    with Image.open(f) as image:
  File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 528, in __getattr__
    raise AttributeError(name)
AttributeError: __exit__
</code></pre>

<p>how resolved this problem  ? </p>

<p>Help on method resize in module PIL.Image:</p>

<pre><code>resize(self, size, resample=0) unbound PIL.Image.Image method
    Returns a resized copy of this image.

    :param size: The requested size in pixels, as a 2-tuple:
       (width, height).
    :param filter: An optional resampling filter.  This can be
       one of :py:attr:`PIL.Image.NEAREST` (use nearest neighbour),
       :py:attr:`PIL.Image.BILINEAR` (linear interpolation in a 2x2
       environment), :py:attr:`PIL.Image.BICUBIC` (cubic spline
       interpolation in a 4x4 environment), or
       :py:attr:`PIL.Image.ANTIALIAS` (a high-quality downsampling filter).
       If omitted, or if the image has mode "1" or "P", it is
       set :py:attr:`PIL.Image.NEAREST`.
    :returns: An :py:class:`~PIL.Image.Image` object.
</code></pre>