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
Windows: image with alpha is not displayed correctly #3695
Comments
Yep, the docs say:
https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.show Note "method is mainly intended for debugging purposes". You can save the image first and then use the viewer of your choice to open it. Alternatively, it's possible to override it to use your own choice of viewer. See ImageShow.py and: Lines 2899 to 2909 in 8194677
|
Perhaps a |
On Mac, I think the problem is the same. If the mode the Image object is If it can not be done, at least there should be a warning that the displayed image is not a faithful representation of the true image. It really took me a while to figure out the problem is that the displayed image is not the same as the true image. |
Actually, Mac switched from BMP to PNG in #2527 and we've not updated the Perhaps we could default to PNG with Windows too. We'd need to make sure (1) we can save everything as PNG, or if not, save as BMP, and (2) this command works:
https://ss64.com/nt/start.html It just tells Windows to open an image file by giving the path to the file, and it'll open it in whatever program is associated with that file type. Usually IrfanView on my Windows machine, but we need it in a format that will open in something default like MS Paint (is that the default option?). A quick look at https://en.wikipedia.org/wiki/List_of_Microsoft_Windows_versions shows Windows 7, 8.1 and 10 are still supported PC versions. I don't know if we need to worry about Windows Server when it comes to showing images. |
It works. I add the following code after class WindowsPNGViewer(Viewer):
format = "PNG"
def get_command(self, file, **options):
return ('start "Pillow" /WAIT "%s" '
'&& ping -n 2 127.0.0.1 >NUL '
'&& del /f "%s"' % (file, file))
register(WindowsPNGViewer, -1) After that, I can show the image with alpha channel correctly. |
End users should also be able to switch to PNG through - from PIL import Image, ImageShow
ImageShow.WindowsViewer.format = "PNG"
im_owl = Image.open("owl.jpg")
im_owl.show() Testing, I find that both BMP and PNG can save - 1, L, P, PA, F, RGB, RGBA, RGBX, CMYK, YCbCr - while PNG can save some modes that BMP can't - for example, LA and I. So I don't think we need to worry about using BMP as a fallback for certain image modes. |
I've created PR #4080 to resolve this. |
What did you do?
The pillow package has a method called
Image.putalpha()
which is used to add or change the alpha channel of an image.I tried to play with this method and found that I can not change the background color of an image. The original image is
This is my code to add alpha to it
What did you expect to happen?
The produced image shows the effect of adding alpha channel to image.
What actually happened?
The produced image is nothing different from the original image. I have tried with different value of alpha and see no difference.
What are your OS, Python and Pillow versions?
After consulting the pillow doc about
Image.show()
method, it seems that pillow will convert the Image object to bmp files and show it with default system image viewer. That explains the reason why no difference between the original and alpha-composited image.It would be great if the image is shown as its original format, not as bmp files.
The text was updated successfully, but these errors were encountered: