Skip to content

Conversation

@henrikmidtiby
Copy link
Contributor

@henrikmidtiby henrikmidtiby commented Jun 26, 2025

Overview: What does this pull request change?

This PR fixes #4256

The set_opacity method now uses both the specified alpha value and the alpha channel in the original image to calculate the alpha channel of the image that is shown in the animation.

Further Information and Comments

The solution is based on PR 2923 by NicoWeio.
This PR mentions that it awaited a solution to how ImageMObject's are hashed.
This does not seem to be needed anymore.

Test code

from manim import * 

class OpacityBug(Scene):
    def construct(self):
        grid = NumberPlane(x_range=(-14, 14), 
                           x_length=7, 
                           y_range=(-10, 10), 
                           y_length=5)
        self.add(grid)

        images = [ImageMobject("pic/transparent_image.png").scale(2) for _ in range(6)]
        images[0].move_to(LEFT*2 + UP)
        images[1].set_opacity(0.80).move_to(UP)
        images[2].set_opacity(0.60).move_to(RIGHT*2 + UP)
        images[3].set_opacity(0.40).move_to(LEFT*2 + DOWN)
        images[4].set_opacity(0.20).move_to(DOWN)
        images[5].set_opacity(0.00).move_to(RIGHT * 2 + DOWN)
        self.add(images[0])
        self.add(images[1])
        self.add(images[2])
        self.add(images[3])
        self.add(images[4])
        self.add(images[5])

Output before change
OpacityBug_ManimCE_v0 19 0

Output after change
OpacityBug_ManimCE_v0 19 0

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

…geMObject and then use it in the set_opacity method

Change from PR 2923 by NicoWeio
@behackl behackl changed the title Handle opacity and transparent images - Fix issue #4256 Handle opacity and transparent images Jun 26, 2025
@behackl behackl added the pr:bugfix Bug fix for use in PRs solving a specific issue:bug label Jun 26, 2025
Copy link
Member

@behackl behackl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you very much!

@github-project-automation github-project-automation bot moved this from 🆕 New to 👍 To be merged in Dev Board Jun 26, 2025
@behackl behackl merged commit 9c43ad0 into ManimCommunity:main Jun 26, 2025
22 checks passed
@github-project-automation github-project-automation bot moved this from 👍 To be merged to ✅ Done in Dev Board Jun 26, 2025
@henrikmidtiby henrikmidtiby deleted the ImageOpacityBug branch June 28, 2025 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:bugfix Bug fix for use in PRs solving a specific issue:bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

set_opacity breaks transparent ImageMObjects

2 participants