python library and cli tool to convert images and videos to ascii.
Project description
asciipy
python library and cli tool to convert images and videos to ascii
Example output:
additional examples can be found in /examples/
Command line usage:
asciipy [input_file] [output_file] [width] (optional, default=80)
Command line examples:
-
image with default size:
asciipy test.png ascii.png
-
video with default size:
asciipy test.mp4 ascii.mp4
-
image with custom size:
asciipy test.png ascii.png 160
-
video with custom size:
asciipy test.mp4 ascii.mp4 160
Optional dependencies (URL and Youtube support):
- note: these libraries can be manually installed instead.
youtube_dl
can be used instead ofyt-dlp
asciipy-any[full]
will installrequests
andyt-dlp
to enable downloading from urls and youtube videos.asciipy-any[url]
will installrequests
to enable downloading from urls.asciipy-any[youtube]
will installyt-dlp
to enable downloading youtube videos.
Python usage:
asciipy provides four classes ImageConverter
, GifConverter
, VideoConverter
, and BaseConverter
- note:
input
fields can accept a url to convert, instead of local media or buffers.
BaseConverter: all other converters inherit from this class.
- takes two positional arguments,
width
, andpalette
. int
width: desired width in ascii characters (height is implicit from the aspect ratio of the input)List[Tuple[int, int, int]]
palette: optional custom color palette, list of RGB tuples. currently 3 palettes are included inasciipy.palettes
.c64
,nes
, andcmd
Methods:
convert
: method called to start conversion.
- takes 2 arguments,
input
, andoutput
, and returnsNone
. os.PathLike, IOBase, str
input: input media to convert. can be a file, iobuffer, or url.os.PathLike, IOBase, str
output: destination of the converted media.
ImageConverter: class used for image conversion.
- takes no extra arguments.
GifConverter: class used for gif conversion.
- takes one extra argument:
bool
gif: if the converted output should be a gif, defaults toTrue
. ifFalse
, the first frame of the gif will be output as a png.
VideoConverter: class used for conversion of videos.
- takes one extra argument:
bool
progress: if a progress indicator should be printed during conversion.
Palettes:
custom color palettes can be provided to the constructor of any converter. it should be a list of rgb tuples. the order of the tuples does not matter, however the order inside the tuple must be RGB, or you will get unintended colors.
example (black and white):
palette = [
(0, 0, 0),
(255, 255, 255)
]
Python examples:
image to ascii cli
from asciipy import ImageConverter
import sys
img = ImageConverter()
img.convert(sys.argv[1], './ascii.png')
print(f"{sys.argv[1]} converted and written to ./ascii.png")
Planned features:
proper gif support(mostly done, but still to buggy to be considered finished)- ability to write output as html
- ability to convert vectors (not sure how i could even go about this)
need help?
-
or my guilded server (i'm often not online here)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for asciipy_any-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ab5cb109d18702407dc1644086522592a1cd86f3505908ef67a93207897fb2b |
|
MD5 | 779891d4254b7aa12b6d5971db31cf29 |
|
BLAKE2b-256 | cc39082ea4437beaadee69bd24c7c12642ef731d2eb81801cc3d2e41df855ec9 |