Search on blog:

Manim: Basic image animations in Manim

Load image and display 3 seconds

from manim import *


class Example(Scene):

    def construct(self):
        self.wait(.1) # to skip animation of first image

        image = ImageMobject('lenna.png')

        self.add(image)
        self.wait(5)


if __name__ == '__main__':
    import subprocess
    subprocess.run(['manim', '-p', '-qh', __file__, 'Example'])

Duplicate image and display in different places

from manim import *


class Example(Scene):

    def construct(self):
        self.wait(.1) # to skip animation of first image

        image1 = ImageMobject('lenna.png')

        self.add(image1)
        self.wait(2)

        #image2 = ImageMobject('lenna.png') # position: center of screen
        #image2 = image1.copy()             # position: last position of image1
        image2 = image1.generate_target()   # position: last position of image1
        image2.shift(4*LEFT)

        self.add(image2)
        self.wait(2)

        #image3 = ImageMobject('lenna.png')
        #image3 = image1.copy()
        image3 = image1.generate_target()
        image3.shift(4*RIGHT)

        self.add(image3)
        self.wait(2)


if __name__ == '__main__':
    import subprocess
    subprocess.run(['manim', '-p', '-qh', __file__, 'Example'])

Display image in different places without animation

from manim import *


class Example(Scene):

    def construct(self):
        self.wait(.1) # to skip animation of first image

        image = ImageMobject('lenna.png')
        self.add(image)

        image.shift(LEFT*3)
        self.wait(1)

        image.shift(RIGHT*6)
        self.wait(1)

        image.shift(LEFT*6)
        self.wait(1)

        image.shift(RIGHT*6)
        self.wait(1)


if __name__ == '__main__':
    import subprocess
    subprocess.run(['manim', '-p', '-qh', __file__, 'Example'])

Move image to different places with animation

from manim import *


class Example(Scene):

    def construct(self):
        self.wait(.1) # to skip animation of first image

        image = ImageMobject('lenna.png')
        self.add(image)

        self.play(image.animate.shift(LEFT*3))

        self.play(image.animate.shift(RIGHT*6))

        self.play(image.animate.shift(LEFT*6))

        self.play(image.animate.shift(RIGHT*3))

        self.wait(1)


if __name__ == '__main__':
    import subprocess
    subprocess.run(['manim', '-p', '-qh', __file__, 'Example'])

Rotate image without animation

from manim import *
import math

class Example(Scene):

    def construct(self):
        self.wait(.1) # to skip animation of first image

        image = ImageMobject('lenna.png')
        image.shift(4*LEFT)   # move left to use `center` for rotation
        self.add(image)
        self.wait(1)

        # --- rotate around center of image ---

        center = image.get_center()

        # rotate right

        for _ in range(3):
            image.rotate(angle=PI/6, about_point=center, axis=IN)
            self.wait(1)

        # rotate left

        for _ in range(3):
            image.rotate(angle=PI/6, about_point=center) # , axis=OUT)
            self.wait(1)

        # --- rotate around center of screen ---

        center = ORIGIN

        # rotate right

        for _ in range(12):
            image.rotate(angle=PI/6, about_point=center, axis=IN)
            self.wait(1)


if __name__ == '__main__':
    import subprocess
    subprocess.run(['manim', '-p', '-qh', __file__, 'Example'])

Rotate image with animation

from manim import *
import math

class Example(Scene):

    def construct(self):
        self.wait(.1) # to skip animation of first image

        image = ImageMobject('lenna.png')
        self.add(image)

        # left 360 degrees (2*PI radians)
        self.play(Rotate(image, angle=2*PI), run_time=3)
        self.wait(1)

        # right 360 degrees (2*PI radians) with `minus`
        self.play(Rotate(image, angle=-2*PI), run_time=3)
        self.wait(1)

        # linear

        # left 360 degrees (2*PI radians)
        self.play(Rotate(image, angle=2*PI, axis=OUT), run_time=3, rate_func=linear)
        self.wait(1)

        # right 360 degrees (2*PI radians)
        self.play(Rotate(image, angle=2*PI, axis=IN), run_time=3, rate_func=linear)
        self.wait(1)

if __name__ == '__main__':
    import subprocess
    subprocess.run(['manim', '-p', '-qh', __file__, 'Example'])

Execution

manim -p -ql main.py Example

where

-p      preview after rendering
-ql     quality low
-qh     quality high

If you like it
Buy a Coffee