Fast means for gif export

Hi everyone,
I am animating mode shapes in Plotly. So it is an animated 3d surface plot. I am able to export some camera angles as gifs but the process is very slow. I assume it is because I am using fig.to_image(format = ‘png’) to export the frames. Would there be a way to export/ grab the raw image?

this is my total code:


        for i,  fig in enumerate(figs):
            frames = []
            fig.update_layout(camera_layout)  #change camera position
            # make sure folder exists
            os.makedirs(self.measurement.paths.plot + 'Shape', exist_ok=True)
            for s, fr in enumerate(fig.frames):
                # set main traces to appropriate traces within plotly frame
                fig.update(data=fr.data)
                # move slider to correct place
                fig.layout.sliders[0].update(active=s)
                # generate image of current state

                stream = io.BytesIO(fig.to_image(format="png"))
                (PIL.Image.open(stream))
                frames.append(PIL.Image.open(stream))

            # define save path
            gif_folder = self.measurement.paths.plot +'Shape/'
            gif_path = gif_folder + str(i) + '_MS_'+ suffix+ str(np.round(self.f_ms[i],2))+'Hz.gif'
            # create animated GIF
            frames[0].save(
                    gif_path,
                    save_all=True,
                    append_images=frames[1:],
                    optimize=False,
                    duration=100,
                    loop=0,
                )

Hey @harzer99 welcoem to the forums!

Maybe interesting: