Code Monkey home page Code Monkey logo

imcat's Introduction

imcat

Preview any size image in a terminal window.

imcat tiger

Platform

Supports Linux, MacOS and Microsoft Windows 10 terminals.

Introduction

Do you ever find yourself logged into a server, over SSH, but there is no X11 connection. And you want to see the contents of an image?

imcat to the rescue!

imcat is a 24-bit image viewer that uses ANSI terminal colours to display any image supported by STB. It automatically resizes to the width of your terminal, using proper sampling kernels.

imcat also works on the latest version of Windows 10.

Usage

$ imcat file1 [file2 .. fileN]

If you want to blend the image with the terminal background, then you need to specify the background color of your terminal. For instance:

$ export IMCATBG="#dad9cc"

Todo

  • Handle alpha-transparency. Requires reading the terminal background colour, somehow. Tricky.

Done

  • Correct for aspect ratio of terminal font.

Building

Unix

On Linux, just use 'make' to build the imcat binary.

Windows 10

On Windows, you need clang.exe from Visual Studio 2017 to build the imcat.exe binary. It's actually quite hard to get that compiler working, so you may just as well grab the pre-built imcat.exe binary.

License

Authors

Bram Stolk.

stb_image.h is by Sean Barrett et al.

Acknowledgements

A shout out to Frogtoss for the idea and help. Thanks!

Gallery

Sample use

imcat's People

Contributors

samanthaclarke1 avatar stolk 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

imcat's Issues

How to Run and Compile on Cygwin

I've managed to compile this on Cygwin (under Win 8.1) using the following patch:

diff --git a/Makefile b/Makefile
index db49cec..f9a1bb7 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,6 @@
 imcat: imcat.c
-       cc -std=c99 -Wall -g -o imcat imcat.c -lm
+       x86_64-w64-mingw32-gcc -std=c99 -Wall -g -o imcat imcat.c -lm
+       #gcc -std=c99 -Wall -g -o imcat imcat.c -lm

 run: imcat
        ./imcat ~/Desktop/*.png
diff --git a/imcat.c b/imcat.c
index 635fbc0..7b681b1 100644
--- a/imcat.c
+++ b/imcat.c
@@ -21,6 +21,12 @@ static unsigned char termbg[3] = { 0,0,0 };

 #if defined(_WIN64)
 #      include <windows.h>
+
+#ifndef ENABLE_VIRTUAL_TERMINAL_PROCESSING
+#define ENABLE_VIRTUAL_TERMINAL_PROCESSING  0x0004
+#endif
+
+
 static void get_terminal_size(void)
 {
        const HANDLE hStdout = GetStdHandle( STD_OUTPUT_HANDLE );

Yeah, you need MinGW for Cygwin.

The output works for a small and original PNG:

The Original:

tiger2_100_96

The Result (in Cygwin Bash):

mintty_2018-12-13_20-35-52

In ConEmu (PowerShell 5.1.1)

conemu64_2018-12-13_20-47-50


  • trying to output the png you included in ./image/*.png silently fails.
    (Please add real png for testing!)
  • Running this in PowerShell fails on most systems not using ConPty or newest ConHost.
    (I.e. on OS < Win10)
  • If your terminal window is smaller (in character count) than the image pixel count (in any direction) the image gets broken up.
  • Also works on ConEmu, but look very ugly!

Segfault

I just compiled your software and I get a segmentation fault when trying to open the example images. Can you help me out?

chymera@bartholin ~/src $ git clone [email protected]:stolk/imcat.git
Cloning into 'imcat'...
remote: Enumerating objects: 69, done.
remote: Total 69 (delta 0), reused 0 (delta 0), pack-reused 69
Receiving objects: 100% (69/69), 587.25 KiB | 1.55 MiB/s, done.
Resolving deltas: 100% (30/30), done.
chymera@bartholin ~/src $ cd imcat/
chymera@bartholin ~/src/imcat $ git rev-parse HEAD
ee82fdbbc3789fd13aad0365b0549bb33ade2f4d
chymera@bartholin ~/src/imcat $ make
cc -std=c99 -Wall -g -o imcat imcat.c -lm
imcat.c: In function ‘get_terminal_size’:
imcat.c:48:12: warning: implicit declaration of function ‘popen’; did you mean ‘fopen’? [-Wimplicit-function-declaration]
   48 |  FILE* f = popen( "stty size", "r" );
      |            ^~~~~
      |            fopen
imcat.c:48:12: warning: initialization of ‘FILE *’ {aka ‘struct _IO_FILE *’} from ‘
int’ makes pointer from integer without a cast [-Wint-conversion]
imcat.c:56:2: warning: implicit declaration of function ‘pclose’; did you mean ‘fclose’? [-Wimplicit-function-declaration]
   56 |  pclose( f );
      |  ^~~~~~
      |  fclose
chymera@bartholin ~/src/imcat $ ./imcat images/imcat_tiger.png 
Segmentation fault (core dumped)
chymera@bartholin ~/src/imcat $ ./imcat images/sampledesktop.png 
Segmentation fault (core dumped)

Feature request: Scale and tile

Idea behind this FR is:
If more than 1 image is to be displayed, then it would be nice if imcat could scale them and display them afterwards.

I imagine one could divide the screen into 4 rectangles and display 2 rows with 2 scales images each (2x2).

Redirect stdout

Testing under Windows 10 ([Version 10.0.17692.1004]) I fail to redirect the output to a file. The file only contains a handful escape sequences.

image

In this case, only 311 bytes were written.

The project is not built using Clang (MacOS, M1).

% make 
cc -D_POSIX_C_SOURCE=2 -std=c99 -Wall -g -o imcat imcat.c -lm
imcat.c:87:4: error: implicitly declaring library function 'snprintf' with type 'int (char *, unsigned long, const char *, ...)' [-Werror,-Wimplicit-function-declaration]
                        snprintf( tripl, sizeof(tripl), "%d;%d;%dm ", r,g,b );
                        ^
imcat.c:87:4: note: include the header <stdio.h> or explicitly provide a declaration for 'snprintf'
1 error generated.
make: *** [imcat] Error 1

My envairement:

% gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: arm64-apple-darwin21.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
% g++ -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: arm64-apple-darwin21.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Terminal-size detection overestimates terminal's height, have to scroll

If I use imcat to display an image, I find that it seems to overestimate the terminal's height, proceeding as if it has more (horizontal) lines than it really does, with the result that I can scroll up and down a few lines to view the image, but I can't see the whole image on screen at once.

An example image I used: https://wikilovesmonuments.org.uk/wp-content/uploads/2020/11/Perch_Rock_Lighthouse_in_rock_pool.jpg

I found that resizing my PuTTY window to be shorter, did not have any effect on the output of imcat. If I resized my PuTTY window to be both shorter and narrower, this had the desired effect of causing imcat to generate a smaller output (so that on restoring it to its full size, I could see the full image at once).

I'm using Ubuntu 20.10/AArch64. On the client side I'm using PuTTY 0.74. I'm not using tmux or GNU Screen or anything like that.

Vagrant SSH to linux guest when using Windows 10 cmd.exe window does not completely work

Here is the scenario:
Assume you have a linux guest that you are managing through Vagrant (Kali in my case).
My host platform is Windows 10. Open a Windows console/command-line (cmd.exe) and start up the linux VM using "vagrant up". Then establish an SSH session on the Windows console using "vagrant ssh".

When you use imcat to view an image in the ssh session, the Windows console window does not interpret the data as desired, and the image doesn't work. Here is a screenshot:

image

If you view the same image in the Kali GUI, from a normal terminal window, it works fine as seen here:

image

As seen in the Vagrant ssh session, here is the $TERM:

root@kali:/opt/imcat# echo $TERM
cygwin
root@kali:/opt/imcat#

macOS or brew?

Hey,

any chance to get this brilliant piece of software as brew formula?

Thanks!

Add a formal open source license

The README currently states:

License

  • Public Domain.

It would be better to use a widely-recognized open source license instead — there's less legal uncertainty around them. See Choose a License for more information 🙂

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.