-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
[Bug]: Background of rotated png is rendered black #29300
Comments
I should have done some more due diligence, the problem is resolved if So is this expected behavior of the interpolation or still a bug that should be fixed? |
I think we should understand how why this is happening before we decide if it is a bug or a feature ;) |
you can change the colour of the background convert the mirror icon to RGBA
(Edit: code formatted) |
@Shivangbijalwan This works as well. I also tested it with a different .png image, which has some transparent sections already, and there this happens. I think this is also dependent on the image type, however this is sort of beyond my capabilities. |
What version of pillow do you have installed? |
@Shivangbijalwan Can you explain a bit why changing the loading image to RGBA works? |
@tacaswell Changing the loding image to RGBA works ..................... |
@maederan201 You're absolutely correct that the behavior seems tied to the image type and how matplotlib handles transparency for certain formats. When working with PNG images that already include transparency, Pillow and matplotlib can sometimes misinterpret the transparency information due to differences in how formats like P (palette-based) or LA (luminance-alpha) store data. This can lead to unexpected results, such as transparent regions being displayed as black. While it does feel like unwanted behavior—likely a quirk in how matplotlib processes image transformations—the convert("RGBA") workaround provides a reliable solution. By explicitly standardizing the image format to RGBA, you remove ambiguities and ensure consistent handling of transparency, even with complex images. It's not ideal that this step is needed, but as you've pointed out, the fix is simple and effective enough to mitigate the issue without significant overhead. |
@Shivangbijalwan Once we have a numpy array the details of loading from the file should not matter. Presumably we should be able to up-convert to add the alpha channel when we do the rotation. Do you want to try opening a PR to do that? I also want to remind people to please not just copy-paste output from LLMs into github. https://matplotlib.org/devdocs/devel/contribute.html#restrictions-on-generative-ai-usage |
@tacaswell "Thanks for the suggestion, but I’m not able to open a PR for this at the moment. However, I’ll keep it in mind for future improvements." |
Bug summary
If I rotate an image, the background of its bounding box is rendered black when rendering as .pdf or .png
Code for reproduction
Actual outcome
Expected outcome
Transparent Bounding Box
Additional information
In the past this was possible, however I don't know which version of matplotlib was used...
Operating system
KDE Neon
Matplotlib Version
3.9.2
Matplotlib Backend
tkagg
Python version
3.12.3
Jupyter version
No response
Installation
pip
The text was updated successfully, but these errors were encountered: