10 ms·
Show HN: a Rust based CLI tool 'imgcatr' for displaying images
cat for images, by RUST
- Samuel_w 2y ago[dead]
- TazeTSchnitzel 2y agoYou could get better resolution in some terminals by using sixels: https://en.wikipedia.org/wiki/Sixel https://en.wikipedia.org/wiki/Sixel I think there's some other methods in particular terminals for displaying images, but I don't remember them.
- warbled_tongue 2y agoYeah, but this is in rust.
- ramon156 2y agoHuh?
- martijnarts 2y agoYou could also probably detect the terminal you're in and use some of their advanced features, like the image protocol in iTerm2[0] or the terminal graphics protocol[1]. 1 also lists alternative programs that do this! [0]: https://iterm2.com/documentation-images.html https://iterm2.com/documentation-images.html [1]: https://sw.kovidgoyal.net/kitty/graphics-protocol/ https://sw.kovidgoyal.net/kitty/graphics-protocol/
- hnlmorg 2y agoThis is how murex works too https://github.com/lmorg/murex/blob/master/config/defaults/profile_any.mx#L683 https://github.com/lmorg/murex/blob/master/config/defaults/p...
- dale_glass 2y agoAnd kitty has icat, which just has image support: https://sw.kovidgoyal.net/kitty/kittens/icat/ https://sw.kovidgoyal.net/kitty/kittens/icat/ I'm really confused about how is it that we're in 2024, Linux is open source from top to bottom, and we're still messing around with rendering images in ASCII. I really wish there was some interest in doing a modern, graphical console. UTF8, antialiasing, graphics, the works.
- eptcyka 2y agoX is literally that.
- mxuribe 2y agoWould you kindly clarify? Did you mean Xterm?
- Tmpod 2y agoI believe they meant X.org, the graphical stack used by most graphical Linux systems.
- baq 2y ago> modern um. I guess the rest applies, but...
- IshKebab 2y agoIt's not though. You have to fiddle around with ports and servers and environment variables. But a drawing API is clearly not the way modern graphics works best. What would be really cool is a terminal that supported low latency streaming video. Then you can do proper GUI apps using any rendering system they want and it will properly integrate with ssh.
- ranger_danger 2y agoXsixel
- deleted 2y ago[deleted]
- berkes 2y agoI do a lot of work in the terminal. And every few weeks I'm wishing for something like "cat for images". "I should write it!". And then realize it already exists and is on my machine. I presume most OSes and distro's have some simple image viewer. Mine, Ubuntu, comes with `eog`. Very rarely, am I on a machine that has no display, and I still need to view some images that live there. Then the workflow becomes convoluted: transfer images to a local machine, or put them in some http-accessible place. For those cases, I think imgcatr would be great. But then it's not available on these machines, so that kindof defeats the purpose again.
- e12e 2y ago> Very rarely, am I on a machine that has no display, and I still need to view some images that live there. X11 forwarding over ssh is an option.
- elliottcarlson 2y agoI was making a similar library (paired with a cli app) in Go a while back with some fun results -- it lead me down a rabbit hole trying to render animated gifs, which has interesting results depending on the terminal being used. I also implemented the resizing of the images to properly scale for the terminal as well. I never actually got around to uploading the repo, but will try to get around to that tonight. Some videos of it in action: https://youtu.be/L2LTPKW6EPw https://youtu.be/L2LTPKW6EPw https://youtu.be/b0CYZyuKLr8 https://youtu.be/b0CYZyuKLr8 https://youtu.be/_VnV96l5Xkc https://youtu.be/_VnV96l5Xkc
- overcrowd8537 2y agoI also did something in dotnet that was a half baked visual media player. Had seek, pause, dynamic resizing, and a frame buffer all implemented, but it was a super naive representation. It was neat to be able to save frames of a movie as ascii text to a text file with or without ansi escape sequences to even view later on a machine without the app.
- hsfzxjy 2y agoI've made one years ago, supporting gif https://github.com/hsfzxjy/i2a-rs https://github.com/hsfzxjy/i2a-rs
- plasticeagle 2y agoIt doesn't seem to work in macos terminal, but it's likely my term environment vars aren't set correctly. I just get a whole pile of random colour, some of which are flashing.
- capitainenemo 2y agoIMO the best results out there are with chafa right now. https://hpjansson.org/chafa/gallery/ https://hpjansson.org/chafa/gallery/ It also has some basic ffmpeg support. And yeah, there are sixels and native rendering of graphics in terminals, but I still find this handy if I'm a couple of tmux sessions deep on a remote server and I need to figure out which graphic is which.
- kernelsanderz 2y agoI just noticed that tmux has some basic sixel support now - https://raw.githubusercontent.com/tmux/tmux/3.4/CHANGES https://raw.githubusercontent.com/tmux/tmux/3.4/CHANGES discovered at https://www.arewesixelyet.com/ https://www.arewesixelyet.com/
- capitainenemo 2y agoI guess it'll take a while for that to propagate. I wonder how well it works with nested tmux sessions and multiple servers. Also I do have the issue with terminals support. Regrettably the assigned work computer is still Windows, and I've been using putty there. If you know of a good sixel terminal for windows.. Anyway, Chafa's results are darn good IMO. The images in the gallery don't I feel showcase how well it matches against organic forms. And it handles a wide variety of images. SVG etc. Even when I have access to pixels, I find on slow connections Chafa can be a decent form of compression :) For example, I was using the ffmpeg patch to play a video remotely to figure out what it was and while I could have relayed it with ssh -YC , Chafa was simply a lot more performant due to it being a lossy transformation. Kinda like playing the video in a VNC session with jpeg loss cranked up to max, but without the need to fire that up.
- sylware 2y ago[flagged]
- chompychop 2y agoAnd then there's this little issue of backward compatibility. :)
- sylware 2y agoBut they are kind of hypocrit, since feature creeps, complex or not, will break compilers via planned obsolescence on 5-10 years cycles. From a reality point of view this 'backward compatibility' is actually a trojan horse for those feature creeps. This is this very toxic cycle which has to broken. Compilers have already standard version switches, namely the migration path towards saner C syntax is to leverage such options: -std=c11 will allow syntax from "legacy C below c11", and for instance -std=c25 will start to enforce a simplified and saner C syntax. Adding feature creeps or fixing C syntax will have the same effect on real life code, but in the case of fixing C syntax, it is going to make compiler easier to write and real-life alternatives will spawns, which is is very good and sane thing.
- ape4 2y agoHerb Stutter's Cpp2 is like that https://github.com/hsutter/cppfront https://github.com/hsutter/cppfront
- sylware 2y agoThe complexity of c++ syntax makes it a lost cause (like rust syntax unfortunately), but the root of this tool is "syntax simplication/sanitazer" too. Acknowleding there is an issue here, a core issue, is growing up, and this tool is part of this trend.
- thesuperbigfrog 2y ago>> Guys, this frenzy of computer languages with ultra-complex syntax requiring absurdely massive and complex compiler infrastructure has to go away. >> Don't you see we need the other way around, namely computer languages with simpler syntax. You can't "wish away" essential complexity. Programming languages can be "simple" or "easy to use", but it's hard to make a programming language that does both because software development has some elements that are complex by nature. There are trade-offs to be made when designing programming languages. Overly simple programming languages are toys. No one uses them for real work because they are too limited or too constrained. Some programming languages like Python and Go (to some degree) hide a lot of complexity and are easy to use for many use cases, but the complexity is still present and becomes visible when you try to do something outside their common uses. Other programming languages (like C, C++, and Rust) hide very little and give the software developer more control in exchange for more complexity. This requires more skill and care but allows for leaner, faster software. Rich Hickey has a great talk that highlights the differences between software that is "simple" versus software that is "easy": https://www.infoq.com/presentations/Simple-Made-Easy/ https://www.infoq.com/presentations/Simple-Made-Easy/
- williamcotton 2y agoIf you're on MacOS an imgcat tool pairs well with an imgpbcopy tool like this: https://github.com/williamcotton/dotfiles/blob/master/bin/impbcopy.swift https://github.com/williamcotton/dotfiles/blob/master/bin/im... Then create a shell function like: imgc() { tee >(imgcat "$@") >(impbcopy -) > /dev/null } So you can: cat image.png | imgc Which will then show the image in the console, and if you switch over to another app you can simply paste in the image. And if you create a new file in Preview it will be the image in the paste buffer!
- throwaway143829 2y agoWhat's the difference between this recipe and `impbcopy image.png`? Is it just for the pixelated effect?
- williamcotton 2y agoI use: https://pypi.org/project/imgcat/ https://pypi.org/project/imgcat/ The VS Code terminal supports both the sixel and iterm image format so you get the actual image. Most of the time I'm using it with my personal CLI graph template language: cat some.csv | plt '[x, y], z { bar 10px [solid red, solid green] }' | imgc So then I see the graph in the console and then I'm ready to save it if I'm happy with the output. If you're curious, here's plt, powered by python and matplotlib under the hood: https://github.com/williamcotton/dotfiles/blob/master/bin/plt https://github.com/williamcotton/dotfiles/blob/master/bin/pl...
- godelski 2y agoStrangely this doesn't work inside tmux... It really seems like there are a lot of issues with rendering images in the cli. I know kitty has a python version too but kitty doesn't play nice with tmux and the dev isn't a fan of tmux[0]. To be fair, I'd love to move away from tmux but I use remote machines all day and I haven't found a good alternative. I don't care about tiling (I can do that in vim, even the terminal), though it is useful (mostly switching sessions for managing workflow context). I'd also love to see someone pick back up mosh (ssh). A critical problem is that if you work on remote machines a lot you probably gotta be able to build some things from source and build into your local bin because you don't have sudo access on the machine. Preferably installs without network access. [0] https://github.com/kovidgoyal/kitty/issues/391 https://github.com/kovidgoyal/kitty/issues/391
- emilsayahi 2y agoI tried this two years ago when I was still actively 'learning' Rust: https://github.com/Dirout/depi https://github.com/Dirout/depi
- wokwokwok 2y ago> cargo install imgcatr I feel very uncomfortable seeing cargo being used as a tool to distribute software. Cargo is a package manager. It should build software. I suppose it’s arguable that it should be able to install developer tooling to help you build things. However, I feel uncomfortable seeing this type of thing. Is the installed binary sandboxed? It is namespaced? Is it shared between projects? What causes it to be updated? Can building a crate update the globally installed version of “foo” by “cargo install” installing a different crate that happens to have a binary with the same name? (Yes, via build.rs, but just as a dependency?) How would I even know? There are so many things wrong with this imo. Building a crate should generally be sandboxed, but this (cargo install as a concept, not this particular app) feels like the goal is the opposite of a sandbox, instead it’s a shared arbitrary named tool that goes into your path by default and gets updated an unknown times. I feel like this is going to bite the rust community in the foot at some point.
- onei 2y agoThe go CLI does exactly the same. Python's pip (via setup.py) will do the same, and in an arguably less transparent way iirc. I don't disagree that there are better ways, but it's good enough to get you off the ground.
- lelandbatey 2y agoTo clarify, cargo is like pip but pip with the --user flag on by default.
- gpm 2y ago`pip --user` still installs things to a per-user-global shared folder, that doesn't exist with cargo. If you're going to compare to pip, it's got to be something like "pip, but everything you build gets its own venv".
- nicce 2y agoIf you install binary blob from the internet, you trust exactly one person and no way to verify if binary matches the source. If you build with cargo, you can at least verify that the current source matches the binary and the trust of the dependencies is decentralized, with many eyes on them. There are better ways, but these better ways just use different package managers. The above is no different than any ”build from source” method.
- S0y 2y agoI loved those image2text ever since I learned about libcaca http://caca.zoy.org/wiki/libcaca http://caca.zoy.org/wiki/libcaca
- timetraveller26 2y agoIf you use the kitty terminal you can use: kitten icat image.jpeg
- cameroncooper 2y agoTerminology (part of Enlightenment) is a fantastic terminal and has image support. https://www.enlightenment.org/about-terminology.md https://www.enlightenment.org/about-terminology.md
- semi-extrinsic 2y agoAh, Enlightenment, that's a blast from the past! I remember using a heavily riced E16 back in the days. I haven't tried it after I fell into the tiling WM rabbit hole 15 years ago. How is it holding up?
- Fileformat 2y agotimg is a really nice similar tool that does pixel graphics in the terminal window if supported, falling back to character graphics if not. The big plus is that it supports SVG images. https://github.com/hzeller/timg https://github.com/hzeller/timg And it is available via brew/apt/etc.
- zamubafoo 2y agoWhile not CLI, I always look for cross platform image viewers and found https://github.com/woelper/oculante https://github.com/woelper/oculante. Had a few woes compiling it due to my laptops configuration, but once compiled it works with everything I would reasonably throw at it.
- HomoJS 2y ago[flagged]
- aumerle 2y agoYes hence our butts are so much more hygenic than yours.
- m0shen 2y agoI love seeing how many people wrote one of these. I've written 2: One to learn golang that plays gifs - https://github.com/moshen/gotermimg https://github.com/moshen/gotermimg And one in perl - https://github.com/moshen/Image-Term256Color https://github.com/moshen/Image-Term256Color
- deleted 2y ago[deleted]
- skyfaller 2y agoI've been using viu, which is also written in Rust: https://github.com/atanunq/viu https://github.com/atanunq/viu How does imgcatr compare? Viu was last updated 5 months ago, imgcatr 3 months ago, not a significant difference. imgcatr is a longer name than viu, requiring more keystrokes to type.
- BitNomad 2y agoIt would be better if the images were more clear.