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

[ bug ] getbbox() #4453

Closed
chiboreache opened this issue Feb 27, 2020 · 1 comment · Fixed by #4454
Closed

[ bug ] getbbox() #4453

chiboreache opened this issue Feb 27, 2020 · 1 comment · Fixed by #4454

Comments

@chiboreache
Copy link

chiboreache commented Feb 27, 2020

Simply won't crop exactly that image, meanwhile with others works fine.

When i move image slightly to right in GIMP and save - it is works again, plain resaving with gimp png defaults - does not helps.

  • OS: Arch Linux Linux 5.4.22-1-lts
  • Python: 3.8.1
  • Pillow: community/python-pillow 6.2.1-1
	from PIL import Image
    png_path = './22-108-20179696.png'
    im = Image.open(png_path)
    im = im.crop(im.getbbox())
    im.save('./test.png')

22-108-20179696

@radarhere
Copy link
Member

Testing, I find that it is trimming black transparent pixels, while you have white transparent pixels - that may sound strange, but yes, there is a difference.

I've created PR #4454 to resolve this.

In the meantime, here is code to change black transparent pixels into white transparent pixels before cropping, in case you are interested -

from PIL import Image
png_path = './22-108-20179696.png'
im = Image.open(png_path)

px = im.load()
for x in range(0, im.width):
	for y in range(0, im.height):
		if px[x, y] == (255, 255, 255, 0):
			px[x, y] = (0, 0, 0, 0)

im = im.crop(im.getbbox())
im.save('./test.png')

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

Successfully merging a pull request may close this issue.

2 participants