2

Recently, I wanted to run a terminal command like "git show <hash>" and save the output to an image, a PNG preferably.

I googled it quite a bit and found some neat tricks, with the import command notably, but nothing that would capture STDOUT and save it as an image.

So, I thought I'd ask the brain trust here on SO. Anyone have a tested and verified solution for Linux?

rjh427
  • 54
  • 1
  • 6
  • 4
    What do you mean by "save it as an image"? Does the file contain image information, or are you looking for something that will convert text to an image of the text? – Barmar Jun 16 '17 at 22:30
  • 1
    If you're looking for a tool that does this automatically, it's not a programming question. Try unix.SE or SuperUser.com. – Barmar Jun 16 '17 at 22:31
  • I meant take the text output that git show a-hash will generate and preserve it as an image, faithfully reproducing all it's gory color and detail. – rjh427 Jun 17 '17 at 00:11
  • `git show` produces text output, not an image. You need a tool that converts text to an image. – Barmar Jun 17 '17 at 00:18
  • Correct, and I've googled that but not found any viable solutions that work on Ubuntu 14.04. – rjh427 Jun 17 '17 at 00:20
  • 1
    LIke I said, the place to ask for tools is SuperUser.com. It's not a programming question. You could write a PHP script that uses the GD/Image functions. But until you actually have some code to show, the question is not appropriate here. – Barmar Jun 17 '17 at 00:22
  • "This one is for programming, that one is for tools" sounds kinda like BS when I look at Stack Exchange's short descriptions for the two forums. What do tools get programmed with, rocks of one type or another? "This is the igneous & basaltic programming forum, go ask in the quartz & granite programming forum." har har har. I asked over there anyway, because why not. *shrug* – rjh427 Jun 28 '17 at 19:27
  • It's true that there's some overlap. My general criteria is if you're just going to type a couple of shell commands, or drag and drop a file, it's a tool, not programming. – Barmar Jun 28 '17 at 19:36
  • And if anyone can use it without having to know the concepts of variables, functions, control structures (if/while/for), etc. then it's clearly not programming. Programmers use text editors, but that doesn't make questions about text editors on-topic here, unless it's specifically related to the process of writing programs. – Barmar Jun 28 '17 at 19:39
  • If anyone can use it without having to know the concepts of variables, functions, control structures..., etc. then it's clearly something that should be easy. Yet, it isn't. Viz, here we are with no solution. – rjh427 Jun 29 '17 at 00:56
  • It should be easy for people who know how to use image processing tools on Linux. A good place to find them would be unix.stackexchange.com or SuperUser.com. – Barmar Jun 29 '17 at 01:02
  • If I realized that what I really had was a gimp question and not anything to do with terminal or a command line utility, I wouldn't have asked anywhere on SE. Feel better? You know, there's something to be said for policing the boundaries but at a certain point, it becomes being a jerk. To wit: if this question was truly inappropriate here, a mod would have closed it as off-topic. You? You're just launching assertions. And you're starting to get on my nerves. So either put up, if you have that authority, or shut up. With lots of capital F's added in for good measure. – rjh427 Jun 29 '17 at 11:52

2 Answers2

2

If all you want to do is save output from git show to a file, just do.

git show <hash>:path/to/image.png > /some/other/path/image.png

If you want to see the image, ImageMagick's display command allows piping from STDIN. So you could do

git show <hash>:path/to/image.png | display
Justin Howard
  • 5,504
  • 1
  • 21
  • 48
  • I tried that, it throws a fatal error: Path 'image.png' does not exist in I'm running Ubuntu 14.04, maybe this works on another distro? – rjh427 Jun 17 '17 at 00:15
  • @user3123081 You're supposed to supply the actual path of an image file in your git repository. – Barmar Jun 17 '17 at 00:19
  • I think Justin doesn't understand what `git show ` does. It shows information about a commit, not the contents of a file. – Barmar Jun 17 '17 at 00:23
  • `path/to/image.png` must be a file in the commit specified by ``. @Barmar, no I understand it fine. The `:`syntax outputs the contents of `` to STDOUT. – Justin Howard Jun 17 '17 at 04:35
2

Not sure what git outputs, but you should be able to adapt this to make a PNG image of that text:

echo "git result" | convert -fill red -background yellow label:@- a.png

enter image description here


An alternative way of achieving the same result is like this:

convert -fill red -background yellow label:"$(git show hash)" a.png

convert (or magick from v7 onwards) is part of the ImageMagick suite installed on most Linuxes and available for macOS and Windows.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • This generates an 18x15 pixel image with yellow background containing the text "@-" and with the filename a.png, not sure where the "git show " data went. – rjh427 Jun 29 '17 at 00:49
  • Please try applying the answers to this question https://stackoverflow.com/q/37957972/2836621 – Mark Setchell Jun 29 '17 at 06:24