Skip to content

Transparent images don't seem to be handled correctly #9473

Description

@long0900

I'm using Pillow 12.1.1, Python 3.14.
I was trying to do some image manipulation steps with some VTF textures. I noticed that some of the transparent ones had erroneous results. For example, this is just reading the raw pixel buffer with Image.frombytes() and showing it:

Image Image

Even when I tried to export the texture to TGA format and open it, Pillow was still showing the same result. However, the texture above was displayed fine when I was using RGB mode.

I have attached the .tga image but I have to add a .txt suffix so github can accept to upload it. (Change the extension to .tga if you want to view it)

door_a.tga.txt

Activity

  1. radarhere commented on Mar 19, 2026

    @radarhere
    Member

    Thanks for the TGA file. I can replicate the problem there.

    I'm slightly confused about your VTF problem though. It looks like you've only uploaded the TGA file and two PNGs, so I don't see how I could replicate anything.

  2. long0900 commented on Mar 20, 2026

    @long0900
    Author

    Lemme try to explain the problem a bit more.

    The VTF (Valve Texture Format) is basically a container for various compressed/uncompressed image formats and their mipmaps. I want to reduce the size of it by resizing then compressing the underlying image if the format is not compressed. My plan was parsing the VTF and get the raw RGB(A) pixel data, converting it into a pillow Image with Image.frombytes() then do the processing.

    The PNG on the left was exported (not exactly, more like copy pasted) by a known good VTF editor from a VTF using DXT5 image format, which supports transparency. The right PNG was generated with Image.show() right after reading the raw data. When converting the Image to RGB mode, pillow showed it fine so I believe there's a problem with transparency handling.

    At first when i thought it was a problem with VTF parsing so i dumped the raw data and did a binary comparison with an image exported by the editor. It was a BMP file, not TGA, but judging from the size, I believe they are just some headers + raw pixel data.
    I stripped the BMP header to make the comparison easier. The binaries were identical so I think there was nothing wrong with VTF parsing.

    The raw pixel data in the TGA I attached should be the starting point to replicate the problem. I also attached the VTF and raw image data in RGBA8888 format if that helps.

    door_a.vtf.txt

    door_a.raw.txt

  3. radarhere commented on Mar 20, 2026

    @radarhere
    Member

    I've created #9478 to resolve this. With that,

    from PIL import Image
    im = Image.open('door_a.tga')
    im.save('out.png')

    gives me

    Image
  4. changed the title [-]Transparent images don't seems to be handled correctly[/-] [+]Transparent images don't seem to be handled correctly[/+] on Mar 20, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions