pythonpython-imaging-library

PIL getcolors returning None for some particular images


I am getting weird behaviour when using PIL, here is my code:

main_img = Image.open(image_url)
all_colors = main_img.getcolors(maxcolors=100000)

when I use this image:

enter image description here

everything works perfectly, but when I use this:

enter image description here

PIL literally returns None. I am very confused.

Note: The second image is absolutely massive, unlike the first.


Solution

  • .getcolors() returns None if the number of colors exceeds a limit, but I never expected any images I used to have over 100000 colors.

    I changed the value to 100 million so I hopefully never face this problem ever again.

    all_colors = main_img.getcolors(maxcolors=100000000)