Skip to content

[ bug ] getbbox() #4453

Closed
Closed

Description

@chiboreache

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

Activity

  1. radarhere commented on Feb 28, 2020

    @radarhere
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions