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

Image.show() on image with mode LA does not show transparency #3868

Closed
gerritholl opened this issue May 24, 2019 · 1 comment · Fixed by #3869
Closed

Image.show() on image with mode LA does not show transparency #3868

gerritholl opened this issue May 24, 2019 · 1 comment · Fixed by #3869
Projects

Comments

@gerritholl
Copy link

gerritholl commented May 24, 2019

When I use Image.show() on an image with mode LA, transparency is not shown. When I use .save(...), the resulting image has transparency included correctly. With mode RGBA, transparency is correctly displayed on .show() (and correctly written on .save(...)).

What did you do?

I used .show() on an image with mode LA.

What did you expect to happen?

I expected it to display an image with transparency:

im1

What actually happened?

It showed an image without transparency:

tmplevyr9u2

What are your OS, Python and Pillow versions?

  • OS: openSUSE 15.0
  • Python: 3.7.3
  • Pillow: 6.0.0
from numpy import linspace, block, concatenate, zeros, full
from PIL import Image

L = linspace(0, 255, 200*200, dtype="u1").reshape(200, 200, 1)
A = block([[zeros((100, 100), "u1"),             full((100, 100), 255, "u1")],
            [full((100, 100), 255, "u1"),
            zeros((100, 100), "u1")]]).reshape(200, 200, 1)
im1 = Image.fromarray((concatenate((L, A), 2)), mode="LA")
im2 = Image.fromarray((concatenate((L, L, L, A), 2)), mode="RGBA")
im1.show()
im2.show()
@radarhere
Copy link
Member

This is not a bug as such. ImageShow is deliberately converting the image from LA to L, removing the transparency.

base = Image.getmodebase(image.mode)
if base != image.mode and image.mode != "1" and image.mode != "RGBA":
image = image.convert(base)

However, the exception for RGBA that you see was added in 74da587. So it seems feasible to do so for LA as well.

However, ImageShow uses the BMP format for Windows, and Pillow cannot save LA as BMP. Looking at https://en.wikipedia.org/wiki/BMP_file_format

The 32-bit per pixel (32bpp) format supports 4,294,967,296 distinct colors and stores 1 pixel per 4-byte DWORD. Each DWORD can define the alpha, red, green and blue samples of the pixel.

I could be wrong, but I think that BMP can't handle greyscale with alpha.

So I've created PR #3869 to allow ImageShow to use the LA mode, except for Windows.

@radarhere radarhere moved this from Backlog to Review/QA in Pillow May 25, 2019
Pillow automation moved this from Review/QA to Closed Jun 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Pillow
  
Closed
Development

Successfully merging a pull request may close this issue.

2 participants