[Python] Problem with modifying image pixel by pixel in Pillow Python

Discussão em 'Python' iniciado por Stack, Julho 20, 2025.

  1. Stack

    Stack Membro Participativo

    I'm running python3 and my code is:

    from PIL import Image

    im = Image.open("image.png")
    pixels = im.load()
    for x in range(im.width):
    for y in range(im.height):
    pixels[x, y] = (50,50,50)

    im.show()


    The code seems to be correct according to the docs but it throws this error:

    File "file.py", line 7, in <module>
    pixels[x, y] = (50,50,50)
    TypeError: color must be int or single-element tuple


    How can a color be a single integer?

    Continue reading...

Compartilhe esta Página