Putting pixels with PIL gives error
<p>Newbie here.
i tried to put some number of pixel with random RGB-colors (like adding noise):</p>

<pre><code>from PIL import Image
import random
img=Image.open('pic.bmp')
randomenter=int(input('Enter numpix: '))
for numpix in range(0, randomenter):
    x=random.randint(0,int(img.size[0]))
    y=random.randint(0,int(img.size[1]))
    r=random.randint(0,255)
    g=random.randint(0,255)
    b=random.randint(0,255)
    img.putpixel((x,y),(r,g,b))
img.show()
</code></pre>

<p>with <code>randomenter=100</code> it works sometimes. with higher values it gets me an error:</p>

<pre><code>Traceback (most recent call last):
  File "D:\study\7sem\GiMS\labs\1laba\123.py", line 11, in &lt;module&gt;
    img.putpixel((x,y),(r,g,b))
  File "C:\Python34\lib\site-packages\pillow-3.3.1-py3.4-win-amd64.egg\PIL\Image.py", line 1512, in putpixel
    return self.im.putpixel(xy, value)
IndexError: image index out of range
</code></pre>

<p>What am I doing wrong?
pic with <code>(800, 500)</code> values</p>

<p>How posted @ÅukaszRogalsk, it solves by editing <code>x</code> and <code>y</code> to <code>img.size[0]-1</code> and <code>img.size[1]-1</code></p>

python python-imaging-library