What did you do?
I'm upgrading Pillow from 7.0.0 -> 8.4.0, and have noticed a discrepancy in what img.getbbox() returns for images that have the RGBA mode. It's worth mentioning that this is part of an upgrade in Python versions as well, from 3.7.9 -> 3.9.7 (although I'm not sure this is a cause).
The toy example that demonstrates the difference:
Pillow 7.0.0 (Python 3.7.9)
my_image = Image.open("/path/to/image.jpg").convert("RGBA")
my_image2 = my_image.point(lambda p: p if p < 220 else 0)
my_image2.getbbox()
# outputs e.g. (83, 10, 134, 152)
Pillow 8.4.0 (Python 3.9.7)
my_image = Image.open("/path/to/image.jpg").convert("RGBA")
my_image2 = my_image.point(lambda p: p if p < 220 else 0)
my_image2.getbbox()
# outputs None
If I remove the conversion to RGBA, however, then I get the same output as I did with 7.0.0.
It's also worth noting that my_image2 is the same image in both versions (i.e. I saved them both and then used ImageChops.difference()).
What did you expect to happen?
I expected the output of getbbox() to be the same as with 7.0.0.
What actually happened?
The output with 8.4.0 is None.
FWIW I noted some additions to the PIL.Image.load() logic between these two versions, which is unsurprising, but could be relevant. I believe load() is called within most functions, including getbbox().

The line that caught my eye was 841 (the one that reads if "transparency" in self.info and mode in ("RGBA", "LA", "PA"):). Unless I'm reading this incorrectly, the addition of the check on mode means that this won't ever evaluate to True, because mode is set back to RGB a few lines above?
What are your OS, Python and Pillow versions?
OS: Mac OS
Python: 3.9.7
Pillow: 8.4
What did you do?
I'm upgrading Pillow from 7.0.0 -> 8.4.0, and have noticed a discrepancy in what
img.getbbox()returns for images that have the RGBA mode. It's worth mentioning that this is part of an upgrade in Python versions as well, from 3.7.9 -> 3.9.7 (although I'm not sure this is a cause).The toy example that demonstrates the difference:
Pillow 7.0.0 (Python 3.7.9)
Pillow 8.4.0 (Python 3.9.7)
If I remove the conversion to RGBA, however, then I get the same output as I did with 7.0.0.
It's also worth noting that
my_image2is the same image in both versions (i.e. I saved them both and then usedImageChops.difference()).What did you expect to happen?
I expected the output of
getbbox()to be the same as with 7.0.0.What actually happened?
The output with 8.4.0 is None.
FWIW I noted some additions to the PIL.Image.load() logic between these two versions, which is unsurprising, but could be relevant. I believe
load()is called within most functions, includinggetbbox().The line that caught my eye was 841 (the one that reads
if "transparency" in self.info and mode in ("RGBA", "LA", "PA"):). Unless I'm reading this incorrectly, the addition of the check onmodemeans that this won't ever evaluate toTrue, becausemodeis set back toRGBa few lines above?What are your OS, Python and Pillow versions?
OS: Mac OS
Python: 3.9.7
Pillow: 8.4