作物杂种动画以匹配内容大小

发布于 2025-01-21 15:28:33 字数 555 浏览 3 评论 0原文

对于以下Manim代码,我想(自动)生成一个仅包含等式eq的动画,周围没有空白空间。我该怎么做?

from manim import *

class EquationScene(Scene):

    def construct(self):
        eq = MathTex('a^2 + b^2 = c^2')
        self.play(Write(eq))
       
        # Crop image here, somehow?

如果不能纯粹是在Manim中进行的,那么我将对其他方法开放,例如使用ImageMagick裁剪图像。 (但是,该方法必须是自动的。我显然不想每次修改它时都必须手动裁剪每张图像。)

另请参阅一个相关的问题在这里

For the following Manim code, I would like to (automatically) produce an animation that only contains the equation eq with no empty space surrounding it. How can I accomplish this?

from manim import *

class EquationScene(Scene):

    def construct(self):
        eq = MathTex('a^2 + b^2 = c^2')
        self.play(Write(eq))
       
        # Crop image here, somehow?

If this cannot be done purely in Manim, I'm open to other approaches, such as using ImageMagick to crop the images. (The method must be automatic, however. I obviously don't want to have to manually crop every image each time I modify it.)

See also a related question here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

新雨望断虹 2025-01-28 15:28:33

这是一个片段,将在渲染后产生一个空的输出映像 - 同时在工作目录中编写文件captured_mobject.png,其中包含所需的输出。

class MobjectCapture(Scene):
    def construct(self):
        mob = Text("This is some text that we would like to capture.")

        padding = 0
        m_width = mob.width + padding
        m_height = mob.height + padding
        p_width = int(m_width * config.pixel_width / config.frame_width)
        with tempconfig({
                "frame_width": m_width,
                "frame_height": m_height,
                "pixel_width": p_width,
                "pixel_height": int(p_width * m_height / m_width)
            }):
            img = mob.get_image()
            img.save("captured_mobject.png") 

Here is a snippet which will, upon rendering, produce an empty output image -- while at the same time writing a file captured_mobject.png in your working directory which contains the desired output.

class MobjectCapture(Scene):
    def construct(self):
        mob = Text("This is some text that we would like to capture.")

        padding = 0
        m_width = mob.width + padding
        m_height = mob.height + padding
        p_width = int(m_width * config.pixel_width / config.frame_width)
        with tempconfig({
                "frame_width": m_width,
                "frame_height": m_height,
                "pixel_width": p_width,
                "pixel_height": int(p_width * m_height / m_width)
            }):
            img = mob.get_image()
            img.save("captured_mobject.png") 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文