Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why getbbox() returns None? #7162

Closed
drunkwcodes opened this issue May 15, 2023 · 3 comments
Closed

Why getbbox() returns None? #7162

drunkwcodes opened this issue May 15, 2023 · 3 comments

Comments

@drunkwcodes
Copy link

What did you do?

I tried to use the following code to chop the image edges, but the getbbox() keeps returning None.

What did you expect to happen?

I tried 9.5.0 and 8.4.0, it all returns None, but it worked and returned a tuple in older version which I can't tell.

What are your OS, Python and Pillow versions?

  • OS: Windows 10
  • Python: 3.10.11
  • Pillow: 9.5.0
from PIL import Image, ImageChops


im1 = Image.open("001-0.png")
im = im1.convert(mode="RGBA")
im1.close()
bg = Image.new(im.mode, im.size, im.getpixel((0, 0)))
diff = ImageChops.difference(im, bg)
diff = ImageChops.add(diff, diff, 2.0, -100)


bbox = diff.getbbox()

assert bbox is not None

001-0

@Yay295
Copy link
Contributor

Yay295 commented May 15, 2023

Because diff is fully transparent.

https://pillow.readthedocs.io/en/stable/releasenotes/7.1.0.html#if-present-only-use-alpha-channel-for-bounding-box

For images with an alpha channel, only the alpha channel is used when calculating the bounding box.

@nulano
Copy link
Contributor

nulano commented May 15, 2023

You may be interested in #4849 / #7123.

@drunkwcodes
Copy link
Author

Thanks for your help. I will use RGB mode instead now and look forward to the PR being merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants