gif-for-cli

repository·master·Indexed 25 days ago

https://github.com/google/gif-for-cli

A command-line tool that converts GIFs, short videos, or Tenor GIF API queries into animated ASCII art using ANSI escape sequences for color support. It supports local files, remote URLs, and Tenor API integration, with customizable display modes, dimensions, and export options.

Tokens
814
Snippets
6
Records
6
Agent score
34%

What's inside gif-for-cli

  1. Install gif-for-cli

    master

    Prerequisites

    Requires Python 3 (with setuptools and pip), zlib, libjpeg, and ffmpeg.

    Install dependencies

    Debian based distros:

    sudo apt-get install ffmpeg zlib* libjpeg* python3-setuptools

    Mac:

    brew install ffmpeg zlib libjpeg python

    To ensure Pillow can be installed via a pre-built wheel, install wheel:

    pip3 install --user wheel

    Install the package

    Via PyPI:

    pip3 install --user gif-for-cli

    From source:

    python3 setup.py install --user
    pip3 install --user gif-for-cli
  2. Configure PATH for gif-for-cli

    master

    If the gif-for-cli command is not found, you may need to add the installation directory to your $PATH. Add the following to your .profile based on your operating system:

    Linux:

    if [ -d "$HOME/.local/bin" ] ; then
        PATH="$HOME/.local/bin:$PATH"
    fi

    Mac: (Adjust the version number as necessary)

    if [ -d "$HOME/Library/Python/3.6/bin/" ] ; then
        PATH="$HOME/Library/Python/3.6/bin/:$PATH"
    fi
    if [ -d "$HOME/.local/bin" ] ; then
        PATH="$HOME/.local/bin:$PATH"
    fi
  3. Query Tenor GIF API via gif-for-cli

    master

    You can search for GIFs or use specific IDs directly through the CLI. This interacts with the Tenor GIF API.

    Get trending GIFs:

    gif-for-cli

    Search by keyword:

    gif-for-cli "Happy Birthday"

    Use a specific GIF ID:

    gif-for-cli 11699608

    Use a Tenor URL:

    gif-for-cli https://tenor.com/view/rob-delaney-peter-deadpool-deadpool2-untitled-deadpool-sequel-gif-11699608
    gif-for-cli "Happy Birthday"
  4. Use gif-for-cli with files or URLs

    master

    You can convert local GIF/video files or remote URLs into animated ASCII art using the CLI or by running it as a Python module.

    CLI usage:

    gif-for-cli path/to/some.gif
    gif-for-cli http://example.com/foo.gif
    gif-for-cli http://example.com/foo.mp4

    Python module usage:

    python3 -m gif_for_cli path/to/some.gif
    gif-for-cli path/to/some.gif
  5. Integrate gif-for-cli into Python projects

    master

    To include animated ASCII GIFs in your own Python CLI tool, import execute from gif_for_cli.execute and call it with the environment, arguments, and a file-like object for output (e.g., sys.stdout).

    import os
    import sys
    
    from gif_for_cli.execute import execute
    
    execute(os.environ,
        ["https://tenor.com/view/yay-pokemon-pikachu-gif-8081211"],
        sys.stdout)
  6. Configure gif-for-cli display options

    master

    Customize how the ASCII art is rendered using the following flags:

    Override display mode: Use --display-mode to force a specific color depth:

    • nocolor
    • 256
    • 256fgbg
    • truecolor

    Example:

    gif-for-cli --display-mode=truecolor 11699608

    Adjust dimensions: Use --rows and --cols to prevent line wrapping. To match your current terminal size:

    gif-for-cli --rows `tput lines` --cols `tput cols` 11699608

    Looping: To loop the animation forever, use -l 0:

    gif-for-cli -l 0 11699608

    Exporting: To save the generated ASCII art as a GIF file:

    gif-for-cli 11699608 --export=foo.gif
    gif-for-cli --rows 10 --cols 100 11699608