Code Monkey home page Code Monkey logo

timg's Introduction

timg logo

Terminal Image and Video Viewer

License: GPL v2   Ubuntu Build macOS Build macOS Brew Building HEAD

A user-friendly terminal image viewer that uses graphic capabilities of terminals (Sixel, Kitty or iterm2), or 24-Bit color capabilities and unicode character blocks if these are not available.

On terminals that implement the sixel protocol, the Kitty Graphics Protocol, or the iTerm2 Graphics Protocol this displays images in full resolution.

But even the fallback block display is usable.

Displays regular images, plays animated gifs, scrolls static images and plays videos.

Useful if you want to have a quick visual check without leaving the comfort of your shell and having to start a bulky image viewer. Sometimes this is the only way if your terminal is connected remotely via ssh. And of course if you don't need the resolution. While icons typically fit pixel-perfect, larger images are scaled down to match the resolution.

The command line accepts any number of image/video filenames that it shows in sequence one per page or in a grid in multiple columns, depending on your choice of --grid. The output is emitted in-line with minimally messing with your terminal, so you can simply go back in history using your terminals' scroll-bar (Or redirecting the output to a file allows you to later simply cat that file to your terminal. Even less -R seems to be happy with it).

Pixelation

On a regular terminal, block-characters are used to output images. Half blocks present pixels color-accurately, and quarter blocks provide a higher spatial resolution at the expense of slightly worse color accuracy. These modes should be compatible with most common terminals that support UTF8 and 24Bit color.

If you are on a Kitty, iTerm2, or wezterm terminal, or a terminal that supports the sixel protocol, images can be shown in full resolution.

-p kitty, -p iterm2, or -p sixel -p quarter -p half

Grid display

Images can be shown in a grid, which is very useful if you quickly want to browse through a lot of images. You can choose to show the filename as title, so it is easy to find exactly the filename you're looking for (The following grid uses --grid=2 and is pixelated -p iterm2).

Grid view of 4 pictures

This is how the same grid looks if no high-res mode is available with - `-p quarter` ...

Synopsis

usage: timg [options] <image/video> [<image/video>...]
Options (most common first):
        -p<pixelation> : Pixelation: 'h' = half blocks    'q' = quarter blocks
                                     'k' = kitty graphics 'i' = iTerm2 graphics
                                     's' = sixel graphics
                         Default: Auto-detect graphics, otherwise 'quarter'.
        --grid=<cols>[x<rows>] : Arrange images in a grid ("contact sheet").
        -C, --center   : Center image horizontally in available cell.
        --title[=<fmt_str>]: Print title above each image. Accepts the following
                         format parameters: %f = full filename; %b = basename
                                            %w = image width; %h = height
                                            %D = internal decoder used
                         If no parameter is given, defaults to "%f"
                         Env-var override with TIMG_DEFAULT_TITLE
        -f<filelist>   : Read newline-separated list of image files to show.
                         Relative filenames are relative to current directory.
                         (-f and -F can be provided multiple times.)
        -F<filelist>   : like -f, but relative filenames considered relative
                         to the directory containing the filelist.
        -b<str>        : Background color to use behind alpha channel. Format
                         color name like 'yellow', '#rrggbb', 'auto' or 'none'.
                        'auto' is terminal background color. (default 'auto').
        -B<str>        : Checkerboard pattern color to use on alpha.
        --pattern-size=<n> : Integer factor scale of the checkerboard pattern.
        --auto-crop[=<pre-crop>] : Crop away all same-color pixels around image.
                         The optional pre-crop is the width of border to
                         remove beforehand to get rid of an uneven border.
        --rotate=<exif|off> : Rotate according to included exif orientation.
                              or 'off'. Default: exif.
        -W, --fit-width: Scale to fit width of available space, even if it
                         exceeds height.
        -U, --upscale[=i]: Allow Upscaling. If an image is smaller than the
                         available frame (e.g. an icon), enlarge it to fit.
                         Optional parameter 'i' only enlarges in integer steps.
        --clear[=every]: Clear draw area first. Optional argument 'every' will
                         clear before every image (useful with -w/-wr,
                         but not with --grid)
        -V             : Directly use Video subsystem. Don't probe image
                         decoding first (useful, if you stream video from stdin)
        -I             : Only  use Image subsystem. Don't attempt video decoding
        -w<seconds>    : Wait time between images (default: 0.0).
        -wr<seconds>   : like above, but wait time between rows in grid.
        -a             : Switch off anti-aliasing (default: on).
        -g<w>x<h>      : Output geometry in character cells. Partial geometry
                         leaving out one value -g<w>x or -gx<h> is possible,
                         the other value it then derived from the terminal size.
                         Default derived from terminal size is 160x50
        -o<outfile>    : Write to <outfile> instead of stdout.
        -E             : Don't hide the cursor while showing images.
        --compress[=level]: Only for -pk or -pi: Compress image data. More
                         CPU use, but less used bandwidth. (default: 1)
        --threads=<n>  : Run image decoding in parallel with n threads
                         (Default 3, 3/4 #cores on this machine)
        --color8       : Choose 8 bit color mode for -ph or -pq
        --version      : Print detailed version including used libraries.
                         (v1.5.3+)
        --verbose      : Print some stats after images shown.
        -h             : Print this help and exit.
        --help         : Page through detailed manpage-like help and exit.

  Scrolling
        --scroll[=<ms>]       : Scroll horizontally (optionally: delay ms (60)).
        --delta-move=<dx:dy>  : delta x and delta y when scrolling (default:1:0)

  For Animations, Scrolling, or Video
  These options influence how long/often and what is shown.
        --loops=<num> : Number of runs through a full cycle. -1 means 'forever'.
                        If not set, videos loop once, animated images forever
                        unless there is more than one file to show.
        --frames=<num>: Only show first num frames (if looping, loop only these)
        --frame-offset=<num>: Start animation/video at this frame
        -t<seconds>   : Stop after this time, independent of --loops or --frames

Examples

timg some-image.jpg                # display a static image
timg -g50x50 some-image.jpg        # display image fitting in box of 50x50 pixel

# Multiple images
timg *.jpg                         # display all *.jpg images
timg --title *.jpg                 # .. show name in title (short option -F)
timg --title="%b (%wx%h)" *.jpg    # show short filename and image size as title
timg --grid=3x2 *.jpg              # arrange in 3 columns, 2 rows in terminal
timg --fit-width --grid=3 *.jpg    # maximize use of column width (short: -W)
timg --grid=3 -t5 *.gif            # Load gifs one by one in grid. Play each for 5sec.

# Putting it all together; making an alias to list images; let's call it ils = 'image ls'
# This prints images two per row with a filename title. Only showing one frame
# so for animated gifs only the first frame is shown statically.
# With hi-res iTerm or Kitty terminals, consider more columns, e.g --grid=4x1
# Put this line in your ~/.bashrc
alias ils='timg --grid=2x1 --upscale=i --center --title --frames=1 '

# ... using this alias on images outputs a useful column view
ils *.jpg *.gif

# Read the list of images to load from a file. One filename per line.
locate "*.jpg" > /tmp/allimg.txt ; timg -f /tmp/allimg.txt

# Show a PDF document, use full width of terminal, trim away empty border
timg -W --auto-crop some-document.pdf
timg --frames=1 some-document.pdf    # Show a PDF, but only first page

# Reading images from a pipe. The filename '-' means 'read from stdin.
# In this example generating a QR code and have timg display it:
qrencode -s1 -m2 "http://timg.sh/" -o- | timg -

# Here, using gnuplot output right in the shell
echo "set terminal png; plot sin(x);" | gnuplot | timg -

# Open an image from a URL. URLs are internally actually handled by the
# video subsystem, so it is treated as a single-frame 'film', nevertheless,
# many image-URLs just work. But some image-specific features, such as trimming
# or scrolling, won't work.
timg --center https://i.kym-cdn.com/photos/images/newsfeed/000/406/282/2b8.jpg

# Sometimes, it is necessary to manually crop a few pixels from an
# uneven border before the auto-crop finds uniform color all-around to remove.
# For example with --auto-crop=7 we'd remove first seven pixels around an image,
# then do the regular auto-cropping.
#
# The following example loads an image from a URL; --auto-crop does not work with
# that, so we have to get the content manually, e.g. with wget. Piping to
# stdin works; in the following example the stdin input is designated with the
# special filename '-'.
#
# For the following image, we need to remove 3 pixels all around before
# auto-crop can take over removing the remaining whitespace successfully:
wget -qO- https://imgs.xkcd.com/comics/a_better_idea.png | timg --auto-crop=3 -

timg multi-resolution.ico   # See all the bitmaps in multi-resolution icons-file
timg --frames=1 multi-resolution.ico  # See only the first bitmap in that file

timg some-video.mp4         # Watch a video.

# Play content of webcam (This assumes video4linux2, but whatever input devices
# are supported on your system with libavdevice-dev)
timg /dev/video0

# If you read a video from a pipe, it is necessary to skip attempting the
# image decode first as this will consume bytes from the pipe. Use -V option.
youtube-dl -q -o- -f'[height<480]' 'https://youtu.be/dQw4w9WgXcQ' | timg -V -

# Show animated gif, possibly limited by timeout, loops or frame-count
timg some-animated.gif      # show an animated gif forever (stop with Ctrl-C)
timg -t5 some-animated.gif                   # show animated gif for 5 seconds
timg --loops=3 some-animated.gif             # Loop animated gif 3 times
timg --frames=3 --loops=1 some-animated.gif  # Show only first three frames
timg --frames=1 some-animated.gif            # Show only first frame. Static image.

# Scroll
timg --scroll some-image.jpg       # scroll a static image as banner (stop with Ctrl-C)
timg --scroll=100 some-image.jpg   # scroll with 100ms delay

# Create a text with the ImageMagick 'convert' tool and send to timg to scroll
convert -size 1000x60 xc:none -fill red -gravity center -pointsize 42 \
        -draw 'text 0,0 "Watchen the blinkenlights..."' -trim png:-   \
      | timg --scroll=20 -

# Scroll direction. Horizontally, vertically; how about diagonally ?
timg --scroll --delta-move=1:0 some-image.jpg  # scroll with dx=1 and dy=0, so horizontally.
timg --scroll --delta-move=-1:0 some-image.jpg # scroll horizontally in reverse direction.
timg --scroll --delta-move=0:2 some-image.jpg  # vertical, two pixels per step.
timg --scroll --delta-move=1:1 some-image.jpg  # diagonal, dx=1, dy=1

# Background color for transparent images (SVG-compatible strings are supported)
# and generally useful if you have a transparent PNG that is otherwise hard
# to see on your terminal background.
timg -b auto some-transparent-image.png  # use terminal background if possible
timg -b none some-transparent-image.png  # Don't use blending
timg -b lightgreen some-transparent-image.png
timg -b 'rgb(0, 255, 0)' some-transparent-image.png
timg -b '#0000ff' some-transparent-image.png

# Checkerboard/Photoshop-like background on transparent images
timg -b lightgray -B darkgray some-transparent-image.png

# .. with adjustable size.
timg -b lightgray -B darkgray --pattern-size=4 some-transparent-image.png
Partially transparent icon on champagne-colored terminal emulator
-b auto -b lightgreen -b lightgreen -B yellow -b none
--pattern-size=1 --pattern-size=4

Include in file browsers

There are many terminal based file-browsers. Adding timg to their configuration is usually straight forward.

# Another use: can run use this in a fzf preview window:
echo some-image.jpg | fzf --preview='timg -E --frames=1 --loops=1 -g $(( $COLUMNS / 2 - 4 ))x$(( $FZF_PREVIEW_LINES * 2 )) {}'

# Use in vifm. ~/.config/vifm/vifmrc
filextype *.avi,*.mp4,*.wmv,*.dat,*.3gp,*.ogv,*.mkv,*.mpg,*.mpeg,*.vob,
         \*.fl[icv],*.m2v,*.mov,*.webm,*.ts,*.mts,*.m4v,*.r[am],*.qt,*.divx,
         \*.as[fx]
        \ {View in timg}
        \ timg --title --center --clear %f,

filextype *.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm
        \ {View in timg}
        \ timg --title --center --clear %f; read -n1 -s -r -p "Press any key to return",

Other fun things

# Also, you could store the output and cat later to your terminal...
timg -g80x40 some-image.jpg > /tmp/imageout.txt
cat /tmp/imageout.txt

# Of course, you can redirect the output to somewhere else. I am not suggesting
# that you rickroll some terminal by redirecting timg's output to a /dev/pts/*
# you have access to, but you certainly could...

# Of course, you can go really crazy by storing a cycle of an animation. Use xz
# for compression as it seems to deal with this kind of stuff really well:
timg -g60x30 --loops=10 nyan.gif | xz > /tmp/nyan.term.xz

# ..now, replay the generated ANSI codes on the terminal. Since it would
# rush through as fast as possible, we have to use a trick to wait between
# frames: Each frame has a 'move cursor up' escape sequence that contains
# an upper-case 'A'. We can latch on that to generate a delay between frames:
xzcat /tmp/nyan.term.xz | gawk '/\[.*A/ { system("sleep 0.1"); } { print $0 }'

# You can wrap all that in a loop to get an infinite repeat.
while : ; do xzcat... ; done

# (If you Ctrl-C that loop, you might need to use 'reset' for terminal sanity)

Terminal considerations

This section contains some details that you only might need to ever look at if the output is not as expected.

Many terminals support direct hi-res image output

The Kitty, iTerm2, and wezterm terminals as well as other modern terminals such as Konsole or the terminal in vscode allow to directly display high-resolution pictures.

If timg is running in such a terminal, it will attempt to auto-detect that feature and use that mode. If your terminal does support the feature but can't be auto-detected, you can explicitly choose the pixelation option in question with command line flag or environment variable (see timg --help). (Please file an issue with timg if auto-detect does not work).

VSCode Terminal

The terminal in vscode to display images in high-resolution, you need to enable the Terminal > Integrated: Enable Images setting in vscode. Otherwise you have to explicitly choose -pq to show the 'block' images.

In tmux

The terminal multiplexer tmux prevents high-resolution images as it filters out the escape codes. However, with some ... workarounds, timg can show such pictures in tmux >= version 3.3 iff in a kitty-terminal.

So if you need hi-res pictures in tmux, use a kitty terminal; you also have to explicitly set the pixelation to -pk (see timg --help for details).

Sixel

Other terminals support an older high-resolution sixel-protocol, which you can choose with -ps. Note, for this to work in xterm, you need to invoke it with xterm -ti vt340.

High resolution and low bandwidth

If watching hi-res videos remotely is too slow (due to high bandwidth requirements or simply because your terminal has to do more work), try setting the environment variable TIMG_ALLOW_FRAME_SKIP=1 to allow timg leaving out frames to stay on track (see timg --help, environment variable section). You can also attempt to set the --compress level higher.

Half block and quarter block rendering

Terminals that do not support high-resolution image output can still show images by virtue of showing colored blocks.

The half block pixelation (-p half) uses the the unicode character [▄](U+2584 - 'Lower Half Block') or [▀](U+2580 - 'Upper Half Block') (depending on the TIMG_USE_UPPER_BLOCK environment variable). If the top and bottom color is the same, a simple space with background color is used.

The quarter block pixelation (-p quarter) uses eight different blocks.

With both of these pixelations, choosing the foreground color and background 24-bit color, timg can simulate 'pixels'. With the half-block pixelation, this can assign the correct color to the two 'pixels' available in one character cell, in the quarter pixelation, four 'pixels' have to share two colors, so the color accuracy is slighlty worse but it allows for higher spatial resolution.

The -p command line flag allows to choose between -p half, -p quarter, also possible to just shorten to -ph and -pq. Default is -pq (see above how this looks like).

Terminals that don't support Unicode or 24 bit color will probably not show a very pleasent output. For terminals that only do 8 bit color, use the --color8 command line option.

Half block: Choice of rendering block

By default, timg uses the 'lower half block' to show the pixels in -p half mode. Depending on the font the terminal is using, using the upper block might look better, so it is possible to change the default with an environment variable. Play around with this value if the output looks poor on your terminal. I found that on my system there is no difference for konsole or xterm but the cool-retro-term looks better with the lower block, this is why it is the default.

In some terminals, such as alacritty (and only with certain font sizes), there seems to be the opposite working better. To change, set this environment variable:

export TIMG_USE_UPPER_BLOCK=1   # change default to use upper block.

(this only will work fully with -p half. In -p quarter mode, there are additional blocks that can't be worked around)

What a problematic choice of block looks like

The image generally looks a bit 'glitchy' if the terminal leaves little space between blocks, so that the wrong background color shows on a single line between pixels. This is likely not intended by the terminal emulator and possibly happening on rounding issues of font height or similar.

Anyway, we can work around it (fully in -p half, partially in -p quarter mode). In the following illustration you see how that looks like. If you see that, change the TIMG_USE_UPPER_BLOCK environment variable.

Glitchy. Change TIMG_USE_UPPER_BLOCK Looks good

Other artifacts

Some terminals leave one pixel of horizontal space between characters that result in fine vertical lines in the image. That can't be worked around, send a bug or better pull request to your terminal emulator.

Wrong font aspect ratio

Usually, timg attempts to determine the font aspect ratio and apply some correction if it is off from the nominal 1:2. But if you notice that the image displayed is not quite the right aspect ratio because of the terminals font used, you can set an environment variable TIMG_FONT_WIDTH_CORRECT with a factor to make it look correctly.

Increasing the visual width by 10% would be setting the value to 1.1 for instance.

export TIMG_FONT_WIDTH_CORRECT=1.1
timg myimage.jpg

This is an environment variable, so that you can set it once to best fit your terminal emulator of choice and don't have to worry about later.

Example
Terminal font too narrow Correct. Here with TIMG_FONT_WIDTH_CORRECT=1.375

Installation

Install pre-built package

Packaging status

Debian-based systems

sudo apt install timg

NixOS or Nix package manager

nix-env -i timg

macOS

brew install timg

Use AppImage

The timg release page also has a minimal binary in the AppImage package format. To keep the size small, it does not include video decoding or some more fancy image formats. It is good for many contexts or if you want to try out timg, but for a full-featured binary, use one from your distribution or build from source.

Build and Install from source

Get dependencies on Debian/Ubuntu

sudo apt install cmake git g++ pkg-config
sudo apt install libgraphicsmagick++-dev libturbojpeg-dev libexif-dev libswscale-dev libdeflate-dev librsvg2-dev libcairo-dev # needed libs

# For sixel output.
sudo apt install libsixel-dev

# If you want to include video decoding, also install these additional libraries
sudo apt install libavcodec-dev libavformat-dev

sudo apt install libavdevice-dev # If you want to read from video devices such as v4l2

sudo apt install libopenslide-dev # If you want to add OpenSlide images support
sudo apt install libpoppler-glib-dev  # if WITH_POPPLER enabled.

sudo apt install pandoc  # If you want to recreate the man page

Get dependencies on NixOS or Nix package manager

The dependencies are set-up in the shell.nix, so you're ready to go opening a nix shell

nix-shell

Get dependencies on fedora

sudo dnf install cmake git g++ pkg-config
sudo dnf install GraphicsMagick-c++-devel turbojpeg-devel libexif-devel libswscale-free-devel librsvg2-devel cairo-devel

# If you want to include video decoding, also install these additional libraries
sudo dnf install libavcodec-free-devel libavformat-free-devel libavdevice-free-devel openslide-devel
sudo dnf install pandoc  # If you want to recreate the man page

Get dependencies on macOS

# Homebrew needs to be available to install required dependencies
brew install cmake git GraphicsMagick webp jpeg-turbo libexif librsvg cairo  # needed libs

# If you want to include video decoding, install these additional libraries
brew install ffmpeg

# If you want to add OpenSlide images support
brew install openslide

brew install pandoc  # If you want to recreate the man page

Get repo and compile timg

In the script below you see that the build system allows for some compile-time choices:

  • WITH_LIBSIXEL Use libsixel to output images in sixel graphics format. Default ON.
  • WITH_VIDEO_DECODING allow for video decoding. Requires ffmpeg-related libraries. You typically want this ON (default)
    • WITH_VIDEO_DEVICE this allows for accessing connected video devices, e.g. you can watch your webcam input (requires WITH_VIDEO_DECODING).
  • WITH_GRAPHICSMAGICK This is the main image loading library so you typically want this ON (default).
  • WITH_TURBOJPEG If enabled, uses this for faster jpeg file loading. You typically want this ON (default).
  • WITH_POPPLER High-quality and faster PDF renderer. Needs poppler and cairo. If not compiled-in, will fallback to GraphicsMagick, but that typically results in lower quality renderings. Typically want this ON (default).
  • WITH_RSVG High-quality SVG renderer. Needs librsvg and cairo. If not compiled-in, will fallback to GraphicsMagick, but that typically results in lower quality renderings. Typically want this ON (default).
  • WITH_OPENSLIDE_SUPPORT Openslide is an image format used in scientific applications. Rarely used, so default off, switch ON if needed.
  • WITH_QOI_IMAGE Allow decoding of Quite Ok Image format QOI. Small and simple, default ON.
  • WITH_STB_IMAGE Compile the simpler STB image library directly into the timg binary in cases where Graphicsmagick is not suitable for dependency pruning reasons; output can be slower and of less quality. It is default ON (default) but will always only attempted after other image loading fails. Turn off if you can use GraphicsMagick and want to reduce potential security vectors.

You can choose these options by providing -D<option>=ON on the cmake command line, see below.

git clone https://github.com/hzeller/timg.git  # Get repo
cd timg                     # Enter the checked out repository directory.
mkdir build                 # Generate a dedicated build directory.
cd build
# cmake with your desired options, see descriptions above
cmake ../ -DWITH_OPENSLIDE_SUPPORT=On
make

# After compilation, you can run from build/src/timg or install on your system with
sudo make install

timg's People

Contributors

coldtobi avatar cpixl avatar dankamongmen avatar dolmen avatar hzeller avatar lromor avatar mestrelion avatar simos avatar soraxas avatar speedy-beaver avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

timg's Issues

Magick Segmentation fault with auto-crop

Not sure if this is an upstream bug, so I will post it here first. Take the following image: jump4 ogg

And run

timg -g 111x2 --auto-crop jump4.ogg.png

In Kitty it is all fine:
image

But in Konsole it escalates:
image

This only happens when both -g and --auto-crop are given.

return not 0 if error

An error shall return not zero in bash.

$ timg a.py; ret_code=$?; echo $ret_code
a.py: Invalid data found when processing input
a.py: couldn't load
0

Example working properly returning a non-zero:

$ viu a.py; ret_code=$?; echo $ret_code
"a.py": The image format could not be determined
1

Thank you for the program, it's awesome and light!

Can't install in Oracle Linux

did git and installing libwebp-dev and GraphicsMagick-c++-devel (libgraphicsmagick++-dev equivalent? https://pypi.python.org/pypi/pgmagick/)
with yum.

But now when I type "make" i'm getting this error:

g++ -o timg timg.o terminal-canvas.o -lGraphicsMagick++
/usr/bin/ld: timg.o: undefined reference to symbol 'CloneImageInfo'
/usr/lib64/libGraphicsMagick-Q16.so.3: error adding symbols: DSO missing from command line
collect2: Fehler: ld gab 1 als Ende-Status zurück
make: *** [timg] Fehler 1

What should I do now? :/

How to detect next frame in the output stream to stdout

Amazing package, Kitty's raw API isn't great for positioning etc so I really appreciate this. I'm trying to use timg inside a mother language's REPL, currently, I'm running timg directly which would take over the stdout, but I also want to have control in case I need to redirect it.

My question is when I'm reading the stdout of timg, is there a separator I can look for so I know to print frame by frame?

Slideshow feature

Given multiple images, timg right now displays them in sequence with a given wait-time -w.

It would be cool if there could be a transition effect (simplest: slide in, similar to the scrolling option).

Animated GIFs might be a problem as they might have a different timing between scroll-interval and their repetition interval. A good first implementation could just stop the animation, do the transition, and - if the next image is also an animated gif - start that animation there.

In this context, the different sizes of images have to be addressed as well. Since everything is in-place, they probably need black bars on the borders, with the image centered in the middle, to fill the given display space.

Snap packaging for timg

Snaps are installation packages than can work across different distributions.

I attach the configuration file for a snap for timg.
timg-snap.zip

I also uploaded the timg snap in the "beta" channel of the Ubuntu Store.
It can be installed (in Ubuntu and other distributions that have snap packages enabled) with

snap install --channel=beta timg

I enabled the strict confinement for the snap. This means that it can only render images that are located in the home directory of the user.

Stuck on large text file

When providing timg with a large text file, even when providing -t or --frames, it uses excessive CPU and calculates seemingly forever. Since I often use it for general file inspection, this is quite annoying.

macOS install instructions

I had success with these:

git clone https://github.com/hzeller/timg.git
cd timg/src
brew install GraphicsMagick webp # required libs.
make
make install

Flexible flow layout to fill space

I want to give timg multiple images scaled to a certain height, and want them to be placed right next to each other without worrying about columns.

How to put this forward for inclusion in Linux distros?

I'm not familiar with how the process works to get software included in Linux distros, but little gem would be at the top of my list. It's small, portable and feels like a fundamental CLI tool to have on all systems.

I'd like to try but not sure where to start - a quick web search didn't help with that either.

Anyone have any ideas?

Make error: "use of undeclared identifier 'clock_nanosleep'"

Received the following error attempting to compile the app in OpenBSD Current (7.0).

 use of undeclared identifier 'clock_nanosleep'
        clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &time_, nullptr);

I imagine this might have something to do with OpenBSD's use of clang and the absence of GCC from the system.

Linux terminal

Maybe it would be possible to add full color by defining a correct $TERM. Regarding the UPPER_BLOCK character, probably it would be possible by using the CJKTTY patch, but I've not been able to enable it... :-/

Build fails: add libwebp-dev dependency

Under 16.04 LTS libgraphicsmagick++-dev seems to depend on libwebp-dev, but it doesn't install it as dependency, so I had to apt-get install libwebp-dev separately, otherwise libwebp-dev lib linking failed.

Best add in "Makefile":

requirements::
   sudo apt-get -y install libwebp-dev libgraphicsmagick++-dev

to be sure.

Can you make clear optional?

Is it really necessary to clear the screen buffer before displaying the image? I want do do:

for f in $(ls *.png); do timg $f; done

and scroll back in the terminal, but in the current version of timg, before each image gets displayed, the terminal buffer gets cleared and only the last image is displayed in the terminal with the above command.

Optimization with Terminator

This repo is great! It works well with ubuntu gnome default terminal.
But I am using Terminator as my terminal, the display is not quite clear. Is there any suggestion that I could optimise the display?

I can't compile on termux

[ 93%] Building CXX object src/CMakeFiles/timg.dir/video-display.cc.o
/data/data/com.termux/files/home/timg/src/video-display.cc:163:20: error: assigning to 'AVCodec *' from 'const AVCodec *' discards qualifiers
av_codec = avcodec_find_decoder(codec_parameters->codec_id);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [src/CMakeFiles/timg.dir/build.make:272: src/CMakeFiles/timg.dir/video-display.cc.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/Makefile2:116: src/CMakeFiles/timg.dir/all] Error 2
make: *** [Makefile:156: all] Error 2

Needs aspect ratio adjust

Typically, the aspect ratio for each pixel is not exactly square, so it would be good if there was an option that describes the ratio. Something like -a 0.97 .

EXIF Rotation not working

Exiftool says:

Orientation                     : Rotate 270 CW

Exif says:

Orientation         |Left-bottom

In graphical programs the image is turned correctly, but timg --rotate=exif does not turn it :/

More customization for text scrolling

timg sometimes allows to scroll text-files, but this functionality is very limited:
From my observations, the file has to end in .txt, even then usually ImageMagick creates a picture instead (which can be prevented with -V), yet not all text-files that ImageMagick would convert are actually scrolled in the end:

image

Furthermore, none of the "Scrolling" flags have any effect whatsoever.

In theory, this text scrolling is a great way to take stock of a bunch of files, but it would be good if it could be explicitly enabled for any file not recognized specifically as media regardless of extensions, and scroll speed customized. An option to only scroll until the image frame is filled would also be nice (which in my experiments usually occurs after 3 frames).

Customize title

I would like to have a way to pass a command for generating the title shown above each image, e.g. to include its size

Undefined reference to symbol 'CloneImageInfo'

Hi,

I can't build, errors are as follows:

LANG=C make
g++ -o timg timg.o terminal-canvas.o `GraphicsMagick++-config --ldflags --libs`
/usr/bin/ld: timg.o: undefined reference to symbol 'CloneImageInfo'
/usr/lib64/libGraphicsMagick-Q16.so.3: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Makefile:7: recipe for target 'timg' failed
make: *** [timg] Error 1

However:

readelf -s /usr/lib64/libGraphicsMagick-Q16.so.3| grep -i CloneImageInfo
   544: 00000000000b7120   823 FUNC    GLOBAL DEFAULT   11 CloneImageInfo

Packages versions:

libwebp-devel-0.5.2-1.fc25.x86_64
GraphicsMagick-1.3.25-6.fc25.x86_64

SO is: Fedora 25

Thanks in advance

Reading from stdin: read and buffer for bytes not to get lost

When we read from stdin, bytes are consumed, however if we are just probing content (e.g. the image subsystem figuring out if something is an image), this will garble the state for the next one.

So if we could buffer these and provide some internal re-wind mechanism, that would be good. Worst case, we've to buffer everything to disk first, but if the API allows enough access to provide data in different ways, we can buffer the first chunks, then later just connect the existing stream. To be figured out.

Missing dependency to GraphicsMagic (not ++).

On my system, fedora 18 x86, libGraphicsMagick++.so does not define CloneImageInfo, so it relies on GraphicsMagick.so but this isn't done automatically. I could only get timg to link once I added -lGraphicsMagick.so.

at src/Makefile

 MAGICK_CXXFLAGS=$(shell GraphicsMagick++-config --cppflags)
+MAGICK_CXXFLAGS+=$(shell GraphicsMagick-config --cppflags)
 MAGICK_LDFLAGS=$(shell GraphicsMagick++-config --ldflags --libs)
+MAGICK_LDFLAGS+=$(shell GraphicsMagick-config --ldflags --libs)

Images next to each other?

When supplying two or more images, it draws them below each other -- is it possible to have them next to each other?

Allow to view videos

Even without sound (initialliy?), just being able to quickly check a video file would be good.

Respect SVG transparency

When viewing an SVG image, a white background is added. This is probably due to the default of ImageMagick which can be changed with the flag -background none :)

URLs are handled by the video subsystem, but image loading should work as well.

The AV subsystem can load content from URLs, however, we should have this functionality in general to download content.

In the simplest case, we can re-use the network handling in the AV libraries if they are somewhat exposed in the API.

Storing in a a tmp file, opening it and handing file-descriptors around to image and video subsystem to easily rewind and read from there could then be the next step.

Add this program to Termux

Due to the absence of most of the dependencies, it is impossible to install this program. Please add Termux support.

More compact output

The output of timg could be more compact for the same rendering: the ANSI sequences are generated with useless leading zeroes.

Here is a simple compressor I'm using as a workaround:

#!/bin/sed -f
s/\([;[]\)00*/\1/g

image preview on vifm

It works fine in termite on arch linux but I am trying to have it preview file in vifm. This is what I have currently

fileviewer *.jpg, *.jpeg
\ /usr/local/bin/timg -g100x100 %c

I am getting an image but it is basically garbage
Does anyone have this working?

Compile error with ffmpeg 5

Compiling with ffmpeg 5.x results in

timg-1.4.3/src/video-display.cc: In member function ‘virtual bool timg::VideoLoader::LoadAndScale(const timg::DisplayOptions&, int, int)’:
timg-1.4.3/src/video-display.cc:163:40: error: invalid conversion from ‘const AVCodec*’ to ‘AVCodec*’ [-fpermissive]
  163 |         av_codec = avcodec_find_decoder(codec_parameters->codec_id);
      |                    ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                        |
      |                                        const AVCodec*

Is CMAKE >= 3.13 really necessary? Refuses to build on Ubuntu 18.04

I'm aware the CMake build was just recently added to the project. But requiring 3.13 is very strict! Ubuntu 18.04, which is still in half its lifetime, ships with 3.10.2. Possibly the same happens in many other distros that are still supported.

Is the build script actually using any CMake features that are not available in 3.10? Is it possible for you guys to downgrade it, so it would build-able out-of-the-box by anyone? Sure, I can edit CMakeLists.txt myself, but that misses the point.

CMake Error at CMakeLists.txt:1 (cmake_minimum_required):
  CMake 3.13 or higher is required.  You are running version 3.10.2


-- Configuring incomplete, errors occurred!

Vertical image scrolling ?

Right now, we only provide horizontal image scrolling. But vertical scrolling would be useful as well.

In fact, any uniform integer steps in (x,y) direction should be considered; 1:1 would mean diagonal for instance.

Support `-p b` for using background colours and/or reverse video

For low-fidelity output, \e[48;5;…m or \e[7;38;5;…m is more likely to produce better-looking results than Unicode block characters. Here's how I'd do it:

$ timg --pixelation=b 1px-solid-red.png | sed s/$'\e'/\\\\e/g
\e[7;38;2;255;0;0m \e[27;39m

Now, I know the readme says this:

Terminals that don't support Unicode or 24 bit color are not supported; they will probably not show a very pleasent output.

… so this rendering mode should emit 2 characters instead of 1 (possibly configurable with an option or environment variable):

Actual image
(4×5 @ 1700%)
Enlarged version
(with pixel boundaries)
With 1 character
Pixel ratio: 1.0
With 2 characters
Pixel ratio: 2.0
H (4×5px) H (4×5px)
█  █
█  █
████
█  █
█  █
██    ██
██    ██
████████
██    ██
██    ██

The trade-off is that images take twice as much space to display, but that might be an acceptable compromise if users are happy with scrolling sideways to see the full image (by piping to less -RS), or if they know the image to be small enough to fit their terminal window.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.