Package: asciipixels
asciipixelsGenerate dynamic ASCII art with images and videos.By Leonardo - UmActuallyasciipixelsis a quick-and-easy library for convertingimagesandvideosto highly customizableASCII art. The library has four primary functions that do all the asciification work, and save the result as an image, gif, or video:image.asciify(),image.dynamic_asciify(),video.asciify()andvideo.dynamic_asciify().For a more granular control of what the program should do, theCoreAsciifierclass (the class behind the primary asciipixels functions) and wrapper functions for both ImageMagick and FFmpeg are also available.What Is 'Dynamic'What really sets the asciipixels library apart is thedynamicfunctionality. In the functionsimage.dynamic_asciify()andvideo.dynamic_asciify()some parameters can change over time. The user can passcallablesthat receive the frame number and return the parameter value, rather than passing the hard-coded value itself. In the example below, thedefinitionparameter increases by 16 units every frame. It is modeled by a very simplelambdaexpression.Basic UsageNote: asciipixelsdependson two particular command-line software:ImageMagickandFFmpeg. If you're a CLI nerd and already have these installed, then go ahead with this guide. If not, go to theInstallationsection.Use the corresponding function depending on your use case:image.asciify()converts image to image. The generated ASCII art is returned as a string and optionally saved in a txt.image.dynamic_asciify()converts image to gif or mp4 video. Supports dynamic parameters.video.asciify()converts video to video.video.dynamic_asciify()converts video to video. Supports dynamic parameters.All four have thepathof the input file as the first argument. The rest of the arguments all havedefault values. Something along these lines is enough to get you started:importasciipixelsasapap.image.asciify('foo.png')This will generate a new asciified image namedfoo2.png.It is important to note thatall functionsexceptimage.asciify()requireaif __name__ == '__main__'check in the top level of the user code (unlessyou are using interactive python on the command line). This is because the library usesmultiprocessingto speed up frame generation. So, in order to asciify a video, for example, you can do the following:importasciipixelsasapif__name__=='__main__':ap.video.asciify('foo.mp4')The most importantparameterto play around with is thedefinition. It is simply the number of characters in thehorizontalaxis. Defaults to 100 in all functions. Set it too high and the ASCII art will just look like art. Set it too low and it will just look like ASCII.Also, keep in mind that you can set theoutput resolutionof the image/video. The output dimensions approximate the input dimensions by default, but you can change that with theout_widthargument.Lastly, if you decide to work withdark texton alight background, remember to setreverse_charstoTruein order to correct the pixel-to-ASCII mapping.As a final example, I made the Bigweld gif in theWhat Is 'Dynamic'section with the following code:importasciipixelsasapif__name__=='__main__':ap.image.dynamic_asciify('ceo.png',bg_color=255,txt_color=0,definition=lambdaf:f*16,fps=2,frame_count=7,out_width=1000,reverse_chars=True)The complete list of parameters/arguments of a given primary function can be found in its documentation.InstallationTo install asciipixels, usepipin the terminal:Windowspip install asciipixelsmacOS / Linuxpython3 -m pip install asciipixelsAsciipixels has twodependenciesthat aren't installed automatically. These areImageMagick, for image manipulation, andFFmpeg, for video and audio manipulation. You can download them from theirofficial sitesor by usingHomebrew(if applicable).Install ImageMagick HereInstall FFmpeg HereCool, But What Is ASCII ArtASCII art is simply the representation of images (or video) withcharactersand letters. This art can be composed by using characters that match either thebrightnessorcontourof a part of an image. This library works with the brightness aspect.