Skip to content

Transparent 1-bit PNG images treated as opaque (alpha component 255) #9281

Description

@peteroupc

This library doesn't recognize transparent pixels as such in images loaded from 1-bit PNGs with a 'tRNS' chunk. The following example loads an 8×2 image, where the first row is transparent and the second row is black. Despite this, when retrieving a pixel from the first row, the alpha component is 255, and not 0 (transparent) as expected.

import base64
import io
import PIL.Image

# 8×2 image: first row transparent, second row black
bio=io.BytesIO(base64.b64decode(
  b'iVBORw0KGgoAAAANSUhEUgAAAAgAAAACAQAAAABN'+\
  b'76BAAAAAAnRSTlMAAQGU/a4AAAAMSURBVHicY/jPwAAAAwEBAMn+'+\
  b'ku8AAAAASUVORK5CYII='))
pi=PIL.Image.open(bio)
# Note: Image has mode '1' and a 'tRNS' chunk
pi2=pi.convert("RGBA")
# alpha component of first row's pixel should equal 0,
# but is 255 instead
print(pi2.getpixel([0,0]))

Activity

  1. radarhere commented on Oct 30, 2025

    @radarhere
    Member

    I've created #9282 to resolve this.

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