Skip to content

set_opacity breaks transparent ImageMObjects #4256

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

Open
Daedo opened this issue May 23, 2025 · 1 comment
Open

set_opacity breaks transparent ImageMObjects #4256

Daedo opened this issue May 23, 2025 · 1 comment

Comments

@Daedo
Copy link

Daedo commented May 23, 2025

Description of bug / unexpected behavior

Calling set_opacity(1) on an image with a transparent background causes that background to become black.
That is because set_opacity incorrectly overwrites the transparency of the image.

Expected behavior

When calling set_opacity(x) the opacity of any given pixel in the image should be x*y where y is the alpha channel of the original unmodified image. Especially any pixel that was fully transparent in the original image should remain transparent no matter how the opacity is modified

How to reproduce the issue

Code for reproducing the problem
config.background_color = WHITE
class OpacityBug(Scene):
    def construct(self):
        image = ImageMobject("Image with Transparent Background.png")
        # The background is displayed correctly
        self.add(image)
        self.wait(1)
        image.set_opacity(1)
        # The background is now a black box
        self.wait(1)

While this example is quite artificially constructed any change to the opacity will cause this issue e.g. Animations that change transparency

Additional media files

Images/GIFs

Image

System specifications

System Details
  • OS (with version, e.g., Windows 10 v2004 or macOS 10.15 (Catalina)): Linux Mint 21.3
  • Python 13.12.10
  • Installed modules (provide output from pip list):
Package             Version
------------------- -----------
anyio               4.9.0
av                  13.1.0
backports.tarfile   1.2.0
beautifulsoup4      4.13.4
Brotli              1.1.0
build               1.2.2.post1
CacheControl        0.14.3
certifi             2025.4.26
cffi                1.17.1
charset-normalizer  3.4.2
cleo                2.1.0
click               8.2.0
cloup               3.0.7
colorama            0.4.6
crashtest           0.4.1
cryptography        45.0.2
decorator           5.2.1
distlib             0.3.9
dulwich             0.22.8
exceptiongroup      1.3.0
fastjsonschema      2.21.1
filelock            3.18.0
findpython          0.6.3
glcontext           3.0.0
h11                 0.16.0
h2                  4.2.0
hpack               4.1.0
httpcore            1.0.9
httpx               0.28.1
hyperframe          6.1.0
idna                3.10
importlib_metadata  8.6.1
importlib_resources 6.5.2
importmonkey        2.1.1
installer           0.7.0
isosurfaces         0.1.2
jaraco.classes      3.4.0
jaraco.context      6.0.1
jaraco.functools    4.1.0
jeepney             0.9.0
keyring             25.6.0
manim               0.19.0
ManimPango          0.6.0
mapbox_earcut       1.0.3
markdown-it-py      3.0.0
mdurl               0.1.2
moderngl            5.11.1
moderngl-window     3.1.1
more-itertools      10.7.0
msgpack             1.1.0
networkx            3.4.2
numpy               2.2.6
packaging           25.0
pbs-installer       2025.4.9
pillow              11.2.1
pip                 25.1.1
pkginfo             1.12.1.2
platformdirs        4.3.8
poetry              2.1.3
poetry-core         2.1.3
pycairo             1.28.0
pycparser           2.22
pydub               0.25.1
pyglet              2.1.6
pyglm               2.8.2
Pygments            2.19.1
pyproject_hooks     1.2.0
PySocks             1.7.1
PyYAML              6.0.2
RapidFuzz           3.13.0
requests            2.32.3
requests-toolbelt   1.0.0
rich                14.0.0
scipy               1.15.2
screeninfo          0.8.1
SecretStorage       3.3.3
setuptools          80.1.0
shellingham         1.5.4
skia-pathops        0.8.0.post2
sniffio             1.3.1
soupsieve           2.7
srt                 3.5.3
svgelements         1.9.6
tomli               2.2.1
tomlkit             0.13.2
tqdm                4.67.1
trove-classifiers   2025.5.9.12
typing_extensions   4.13.2
urllib3             2.4.0
virtualenv          20.31.2
watchdog            6.0.0
wheel               0.45.1
zipp                3.21.0
zstandard           0.23.0
@jecelyin
Copy link

same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 New
Development

No branches or pull requests

2 participants