Hey, guys! Newbie here. =) I try to reverse an image but an error came and i don't know why :/
This is the error:

Traceback (most recent call last):
  File "C:/Users/Florian/Documents/ISN/S10/défi11.py", line 10, in <module>
    im.putpixel((x,600-y),(p[0],p[1],p[2]))
  File "C:\Python27\lib\site-packages\PIL\Image.py", line 1267, in putpixel
    return self.im.putpixel(xy, value)
IndexError: image index out of range

And the prog:

# -*- coding: cp1252 -*-
from PIL import Image

im=Image.open("H:\Belem.png")
L,H=im.size
for y in range(H):

    for x in range(L):
        p=im.getpixel((x,y))
        im.putpixel((x,600-y),(p[0],p[1],p[2]))

im.save("H:\defi11.png")

Use a copy of image
im2 = im.copy()
Then in the loop try ...
im2.putpixel((x, H-y-1),(p[0], p[1], p[2]))

A simpler option ...

# flip the image around a horizontal axis
im_flipped = im.transpose(Image.FLIP_TOP_BOTTOM)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.