Coder Social home page Coder Social logo

hzeller / timg Goto Github PK

View Code? Open in Web Editor NEW
1.8K 27.0 67.0 2.99 MB

A terminal image and video viewer.

License: GNU General Public License v2.0

C++ 93.73% CMake 5.95% Nix 0.20% Shell 0.12%
ascii-art gif image image-viewer iterm2 jpeg kitty-terminal png terminal unicode-art

timg's People

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

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.

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... :-/

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.

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

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!

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 .

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.

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)

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.

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?

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.

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?

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.

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.

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? :/

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?

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.

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

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?

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*

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

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!

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 :)

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).

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.

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

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

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.

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?

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.

Allow to view videos

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

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.

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.