A PIL Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ray

    #1

    A PIL Question

    Hello,

    I'm using latest PIL version with Python 2.4.1. (for solving a level in
    Python Challenge actually...). Anyway, I'm trying to draw a picture. My
    question is, why is it that putdata() won't work? Even this won't run:

    import Image

    im = Image.open("som ething.jpg")
    seq = im.getdata()

    image = Image.Image()
    image.putdata(s eq)

    image.show()

    I always get:

    Traceback (most recent call last):
    File "Script1.py ", line 31, in ?
    image.putdata(s eq)
    File "D:\Development \Python24\Lib\s ite-packages\PIL\Im age.py", line
    1120, in putdata
    self.im.putdata (data, scale, offset)
    AttributeError: 'NoneType' object has no attribute 'putdata'

    Anybody has any idea why this is the case?

    Thanks,
    Ray

  • Max Erickson

    #2
    Re: A PIL Question

    "Ray" <ray_usenet@yah oo.com> wrote in
    news:1124040878 .557813.311900@ g47g2000cwa.goo glegroups.com:
    [color=blue]
    >
    > image = Image.Image()[/color]
    [color=blue]
    >
    > Anybody has any idea why this is the case?
    >[/color]

    Image.Image() isn't the way to get a new image object in PIL. Try
    Image.new(), which needs at least mode and size arguments. You can get
    those from your original image...
    [color=blue][color=green][color=darkred]
    >>> from PIL import Image[/color][/color][/color]
    (skip me loading an image into im)[color=blue][color=green][color=darkred]
    >>> im[/color][/color][/color]
    <PIL.JpegImageP lugin.JpegImage File instance at 0x00A8A170>[color=blue][color=green][color=darkred]
    >>> im.mode[/color][/color][/color]
    'RGB'[color=blue][color=green][color=darkred]
    >>> im.size[/color][/color][/color]
    (510, 800)[color=blue][color=green][color=darkred]
    >>> im2=Image.new(i m.mode,im.size)
    >>> seq=im.getdata( )
    >>> im2.putdata(seq )[/color][/color][/color]

    Then do im2.show() and everything should be ok.


    max

    Comment

    • Terry Hancock

      #3
      Re: A PIL Question

      On Sunday 14 August 2005 12:34 pm, Ray wrote:[color=blue]
      > import Image
      >
      > im = Image.open("som ething.jpg")
      > seq = im.getdata()
      >
      > image = Image.Image()
      > image.putdata(s eq)
      >
      > image.show()
      >
      > I always get:
      >
      > Traceback (most recent call last):
      > File "Script1.py ", line 31, in ?
      > image.putdata(s eq)
      > File "D:\Development \Python24\Lib\s ite-packages\PIL\Im age.py", line
      > 1120, in putdata
      > self.im.putdata (data, scale, offset)
      > AttributeError: 'NoneType' object has no attribute 'putdata'
      >
      > Anybody has any idea why this is the case?[/color]

      Well, obviously you didn't get an image back from Image.Image().
      In fact, I suspect you would've at least have to have given it a size
      or something. It clearly returned None, and you're trying to call
      a method that None doesn't have, like it says.

      Definitely check the PIL manual for what Image.Image() is
      supposed to return, and what it requires to have valid output.

      --
      Terry Hancock ( hancock at anansispacework s.com )
      Anansi Spaceworks http://www.anansispaceworks.com

      Comment

      Working...