PIL's thumbnail function returns NoneType

Discussion in 'Python' started by Mirat Can Bayrak, Mar 1, 2009.

  1. Can you try it? it is about me or it is a bug?

    In [1]: import Image

    In [2]: im = Image.open("r.png")

    In [3]: type(im)
    Out[3]: <type 'instance'>

    In [4]: thm = im.thumbnail((200,200))

    In [5]: type(thm)
    Out[5]: <type 'NoneType'>


    --
    Mirat Can Bayrak <>
    Mirat Can Bayrak, Mar 1, 2009
    #1
    1. Advertising

  2. Mirat Can Bayrak <> writes:

    > Can you try it? it is about me or it is a bug?


    Neither. im.thumbnail() modifies the existing image object by
    converting it to a thumbnail. In Python such methods by convention
    return None.

    The documentation explicitly mentions that:

    Also note that this function modifies the Image object in
    place. If you need to use the full resolution image as well, apply
    this method to a copy of the original image. This method returns
    None.

    > In [4]: thm = im.thumbnail((200,200))
    >
    > In [5]: type(thm)
    > Out[5]: <type 'NoneType'>


    Instead of thm, simply keep using ihm.
    Hrvoje Niksic, Mar 1, 2009
    #2
    1. Advertising

  3. Mirat Can Bayrak

    Terry Reedy Guest

    Hrvoje Niksic wrote:
    > Mirat Can Bayrak <> writes:
    >
    >> Can you try it? it is about me or it is a bug?

    >
    > Neither. im.thumbnail() modifies the existing image object by
    > converting it to a thumbnail. In Python such methods by convention
    > return None.
    >
    > The documentation explicitly mentions that:
    >
    > Also note that this function modifies the Image object in
    > place. If you need to use the full resolution image as well, apply
    > this method to a copy of the original image. This method returns
    > None.


    Indeed, the purpose of returning None is to remind that the method does
    mutation in place.


    >
    >> In [4]: thm = im.thumbnail((200,200))
    >>
    >> In [5]: type(thm)
    >> Out[5]: <type 'NoneType'>

    >
    > Instead of thm, simply keep using ihm.
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >
    Terry Reedy, Mar 1, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Lozzi
    Replies:
    1
    Views:
    493
    john smith
    Feb 1, 2006
  2. Roger
    Replies:
    2
    Views:
    275
    Fuzzyman
    Sep 11, 2005
  3. Replies:
    1
    Views:
    503
  4. Jordan Harry
    Replies:
    1
    Views:
    476
    Sean DiZazzo
    May 2, 2008
  5. Replies:
    2
    Views:
    212
    Dave Angel
    May 3, 2013
Loading...

Share This Page