Skip to content

Commit 260d009

Browse files
committed
Restore --save_pngs functionality
1 parent 16bb06d commit 260d009

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

manimlib/scene/scene_file_writer.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import _thread as thread
77
from time import sleep
88
import datetime
9+
from PIL import Image
910

1011
import manimlib.constants as consts
1112
from manimlib.constants import FFMPEG_BIN
@@ -37,7 +38,6 @@ class SceneFileWriter(object):
3738
"""
3839
CONFIG = {
3940
"write_to_movie": False,
40-
# TODO, save_pngs is doing nothing
4141
"save_pngs": False,
4242
"png_mode": "RGBA",
4343
"save_last_frame": False,
@@ -56,6 +56,7 @@ def __init__(self, scene, **kwargs):
5656
self.stream_lock = False
5757
self.init_output_directories()
5858
self.init_audio()
59+
self.frame_count = 0
5960

6061
# Output directories and files
6162
def init_output_directories(self):
@@ -66,7 +67,7 @@ def init_output_directories(self):
6667
"""
6768
module_directory = self.output_directory or self.get_default_module_directory()
6869
scene_name = self.file_name or self.get_default_scene_name()
69-
if self.save_last_frame:
70+
if self.save_last_frame or self.save_pngs:
7071
if consts.VIDEO_DIR != "":
7172
image_dir = guarantee_existence(os.path.join(
7273
consts.VIDEO_DIR,
@@ -334,6 +335,10 @@ def write_frame(self, frame):
334335
"""
335336
if self.write_to_movie:
336337
self.writing_process.stdin.write(frame.tostring())
338+
if self.save_pngs:
339+
path, extension = os.path.splitext(self.image_file_path)
340+
Image.fromarray(frame).save(f'{path}{self.frame_count}{extension}')
341+
self.frame_count += 1
337342

338343
def save_final_image(self, image):
339344
"""

0 commit comments

Comments
 (0)