#!/usr/bin/env python# -*- coding: utf-8 name> -*-"""This script animates a GIF image in text art."""frompathlibimportPathimporttimefromPILimportImagefrompicharssoimportnew_drawerfrompicharsso.utilsimportclear_screen,terminal_sizeif__name__=="__main__":# Choose image# image_path = "<path/to/image>"image_path=Path(__file__).parent/("nyan.webp")# Open imageimage=Image.open(image_path)# Get terminal heightheight,_=terminal_size()# Choose an art stylestyle="gradient"# or "braille"# Define drawerdrawer=new_drawer(style,height=height,colorize=True)# Iterate over framestexts=[]forframe_idinrange(image.n_frames):# Select frameimage.seek(frame_id)# Save output for frametexts.append(drawer(image))# Iterate over saved outputs in a circular mannernum_frames=len(texts)counter=0whileTrue:# Refreshclear_screen()# Print outputprint(texts[counter])# Set a delay between framestime.sleep(1/num_frames)# Circular incrementcounter=(counter+1)%num_frames
Result
Consider the following image:
Nyan Cat
The output of the above script should look like this: