0

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")
2
Contributors
2
Replies
18
Views
2 Years
Discussion Span
Last Post by vegaseat
0

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]))

Edited by vegaseat

0

A simpler option ...

# flip the image around a horizontal axis
im_flipped = im.transpose(Image.FLIP_TOP_BOTTOM)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.