2

So I have a list of 4 .png files, and I'd like to auto-pipe this to some document that puts them all side-by-side for easy comparison.

I'm thinking of automatically putting them in a HTML file. So I'd like to use terminal commands to automatically put for each of the 4 .png files.

How would I best do this via the command line?

2 Answers 2

3

Here's a hacked together script that will do what you want.

$ ( echo -e "<html>\n<body>"; \ for i in {1..4}.png;do echo "<img src="$i">"; done ; \ echo -e "</body>\n</html>" ) | tee 4v.html <html> <body> <img src=1.png> <img src=2.png> <img src=3.png> <img src=4.png> </body> </html> 

To display the resulting file, 4v.html:

$ xdg-open 4v.html 

And the final product:

            ss #1

Adjustments

If you want to use a different series of .png images merely change the arguments to the for loop.

for i in {1..4}.png;do echo "<img src="$i">"; done 

The files are named 1.png, 2.png, 3.png, and 4.png in my example. So if they were all in a directory by themselves you could do this instead:

for i in *.png;do echo "<img src="$i">"; done 
2
  • Awesome - thanks very much! What if the image names were all contained in an external text file? Commented May 15, 2014 at 4:27
  • 1
    @InquilineKea - if there are no spaces in the file names you can use this: for i in $(< file.txt); do .... Commented May 15, 2014 at 13:02
0

Try:

$ cat > compare.html <<EOF html img tags etc EOF 

See how does cat << EOF work in bash?

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.