TastelessStudent
TastelessStudent

Reputation: 31

Encounted an error within my code, however I cannot identify the cause. (getpixel() takes 2 positional arguments but 3 were given)

I am programming for a project, so that I can easily identify how many pixels I want to pad an image for websites. However, I have encountered this error: getpixel() takes 2 positional arguments but 3 were given. My code is as follows:

from PIL import Image
import PIL.ImageOps


background = Image.open("background.png")
target = input("Please enter the name of your image (including file type)")
targetImage = Image.open(target)
area = targetImage.size
targetColouredCoords = []


newArea = (area[0] + 1, area[1] + 1)
borderedTarget = PIL.ImageOps.expand(targetImage, border=10, fill="black")
targetValues = list(borderedTarget.getdata())


def analyser():
    pixelOne = 1
    pixelTwo = 1
    completedSearch = 0
    currentPixel = borderedTarget.getpixel(pixelOne, pixelTwo)

    def colourChecker():
        if currentPixel != (0, 0, 0):
            targetColouredCoords.append((pixelOne, pixelTwo))

    while completedSearch != len(targetValues):
        while pixelOne != newArea[0]:
            while pixelTwo != newArea[1]:
                colourChecker()
                pixelTwo += 1
                completedSearch += 1
            pixelTwo = 1
            pixelOne += 1


analyser()

The only line where I provide 3 arguments in the entire code is 18, but I do not understand how this line of code is incorrect, or how the code highlighted as a problem (line 26) is either. I cannot continue to code until I have removed the error, so any help is greatly appreciated.

Upvotes: 3

Views: 5277

Answers (1)

Ben A
Ben A

Reputation: 799

Just looked again, the input has to be a tuple:

getpixel( (pixelOne,pixelTwo) )

Source

Upvotes: 3

Related Questions