Package: to-ascii
To-AsciiConverts videos, images, gifs, and even live video into ascii art!Works on most image and video types including GIFsWorks on LIVE VIDEO[DEMO SITE][Video Example][Video Example 2]InstallationVia pip:pip install to-ascii[speedups,cli]Thespeedupsextra is recommended,see belowThecliextra is required for CLI use (it addsclickas a dependency)CLI UsageUsage: toascii [OPTIONS] {image|video} SOURCE {colorconverter|colorconverternim|grayscaleconverter|grayscaleconverternim|htmlcolorconverter|htmlcolorconverternim}

Options:
  -g, --gradient TEXT
  -w, --width INTEGER RANGE       [x>=1]
  -h, --height INTEGER RANGE      [x>=1]
  --x-stretch, --xstretch FLOAT RANGE
                                  [x>0.0]
  --y-stretch, --ystretch FLOAT RANGE
                                  [x>0.0]
  --saturation FLOAT RANGE        [-1.0<=x<=1.0]
  --contrast FLOAT RANGE          [0.0<=x<=1.0]
  --blur INTEGER RANGE            [x>=2]
  --loop
  --help                          Show this message and exit.CLI Examples# live videotoasciivideo0colorconverternim-h103--x-stretch3.5--blur10--contrast0.01--saturation0.0toasciiimagesammie.jpggrayscaleconverter-h32--x-stretch2.1--blur20--contrast0.0--saturation0.0toasciivideoIMG_7845.MOVcolorconverternim-h81--x-stretch2.5--blur15--contrast0.01--saturation0.0--loopAPI ReferenceUsage Examples FolderclassConverterOptions(*,gradient:str,width:Optional[int],height:Optional[int],x_stretch:float,y_stretch:float,saturation:float,contrast:Optional[float])pydantic model for converter optionsParameters / Attributes:gradient:str-string containing the characters the converter will use when converting the image to asciimust be at least one characterwidth:Optional[int]-width in characters of the final converted imagedefault value isNonemust be greater than0height:Optional[int]-height in characters of the final converted imagedefault value isNonemust be greater than0x_stretch:float-how much to stretch the width bydefault value is1.0(which doesn't change the width by anything)must be greater than0.0y_stretch:float-how much to stretch the height bydefault value is1.0(which doesn't change the height by anything)must be greater than0.0saturation:float-how much to adjust the saturationdefault value is0.5(which increases the saturation)must be between-1.0and1.0,0.0is no change to saturationcontrast:Optional[float]-how much to increase the contrast bydefault value isNone(which doesn't apply any contrast filter)must be between0.0and1.0blur:Optional[int]-how much to blur the image bydefault value isNone(which doesn't apply any blur)must be greater than0classConverterBase(options:ConverterOptions)base class for implementing convertersParameters:options:ConverterOptions-Options used when converting mediaMethods:abstractasciify_image(image:numpy.ndarray) ->strcalculate_dimensions(initial_height:int,initial_width:int) ->Tuple[int, int]apply_opencv_fx(image:numpy.ndarray, *,resize_dims:Optional[Tuple[int, int]]) ->numpy.ndarrayImplementations:GrayscaleConverter-converts media to grayscale asciiGrayscaleConverterNim-converters media to grayscale ascii, see theExtensionssectionColorConverter-converts media to colored ascii usingColoramaColorConverterNim-converts media to colored ascii usingColorama, see theExtensionssectionHtmlColorConverter-converts media to ascii in colored html spansHtmlColorConverterNim-converts media to ascii in colored html spans, see theExtensionssectionclassImage(source:Union[str, bytes, IOBase],converter:BaseConverter)class for converting an image to asciiParameters:source:Union[str, bytes, IOBase]-the source of the image that is to be loaded and convertedifsourceis astr, it's assumed that it's a path to an image fileifsourceisbytesorIOBaseit's assumed to be the data of an image and is decoded in-memoryconverter:ConverterBase-the converter used to convert the imagetakes anything that implementsConverterBaseMethods:to_ascii() ->strreturns the image converted by the converterview() ->Noneprints out the converted image to the consoleclassVideo(source:Union[str, int, bytes, IOBase],converter:BaseConverter, *,fps:Optional[float],loop:bool)class for converting a video to asciiParameters:source:Union[str, int bytes, IOBase]-the source of the video that is to be loaded and convertedifsourceis astr, it's assumed that it's a path to an image fileifsourceisbytesorIOBaseit's assumed to be the data of an image and is written to a temporary file before being loaded and decoded by OpenCVifsourceis anint, it's assumed to be the index of a camera deviceseeOpenCV'sVideoCapturefor more informationconverter:ConverterBase-the converter used to convert the imagetakes anything that implementsConverterBasefps:Optional[float]-the fps to play the video atdefault value isNoneifNonethen the fps used is fetched from OpenCV'sVideoCaptureAPIloop:bool-whether or not to loop the video when it's done playingdefault value isFalseif the video source is live, this parameter is ignoredMethods:get_ascii_frames() ->Generator[str, None, None]-returns a generator which yields each ascii frame as it is convertedview() ->None-prints out each frame of the converted videoif the video source is not live, this method will first generate all frames and cache them in memory for a smoother playbackif theloopparameter was set toTrueearlier, then this will play the video and restart it when it finishes unless the source is liveExtensionsFor each converter available, there is a separate implementation written inNimThese implementations are generally orders of magnitude faster than their Python counterpartsTo use these extensions you mustinstall Nimand install theto-ascii[speedups]package via pip or your package manager of choice