LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 06-04-2005, 12:02 AM   #1
infidel
Member
 
Registered: Jun 2003
Location: Easley, SC, US
Distribution: Ubuntu 7.10, Mandrake 9.2
Posts: 91

Rep: Reputation: 15
Question Script or Simple App to Create HTML Table Populated With Images


Hello, everyone. I've Googled this one, and everything I've seen thus far is way more than what I need.

Here's the problem: I have a directory containing 77 very small images. I want to put those images in a 7 columns by 11 rows table in HTML; and I'd rather not have to code the thing by hand. All I want is the finished code for the table; I can go back in and modify URLs as needed.

There is no shortage of applications out there that would do this; trouble is, they would do a heck of a lot more, as well. Don't need thumbnails, don't need a nicely-formatted, fancy webpage-- I just want a codeblock that I can cut and paste into another HTML document. Can anyone suggest a script or a simple application that would do this?

Any guidance would be greatly appreciated; thanks very much in advance.
 
Old 06-04-2005, 03:38 AM   #2
Simon Bridge
Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 197Reputation: 197
For really simple ...

But presumably you know this one.
Code:
<table>

<caption>77 Pics</caption>

<tr>
<td align="center"> <img src="image01.png"> </td>
<td align="center"> <img src="image02.png"> </td>
<td align="center"> <img src="image03.png"> </td>
<td align="center"> <img src="image04.png"> </td>
<td align="center"> <img src="image05.png"> </td>
<td align="center"> <img src="image06.png"> </td>
<td align="center"> <img src="image07.png"> </td>
<td align="center"> <img src="image08.png"> </td>
<td align="center"> <img src="image09.png"> </td>
<td align="center"> <img src="image10.png"> </td>
<td align="center"> <img src="image11.png"> </td>
</tr>

[repeat above structure 7 times - copy and paste saves time]

</table>
If you like I could write you a c program which will read images from a directory and then write the html code for a table of those images.

I don't know why you're allergic to coding it up yourself, this took 5 mins.

Last edited by Simon Bridge; 06-04-2005 at 03:42 AM.
 
Old 06-04-2005, 07:37 AM   #3
infidel
Member
 
Registered: Jun 2003
Location: Easley, SC, US
Distribution: Ubuntu 7.10, Mandrake 9.2
Posts: 91

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by Simon Bridge

I don't know why you're allergic to coding it up yourself, this took 5 mins. [/B]
Which is exactly what I ended up doing.

As for being "allergic", you know us slightly-post-newbie intermediate types: we want things NOW.

I was actually hoping that I might find something I could re-use in the future (I'm likely to be doing this kind of thing a lot, with more than 77 images at a time)-- and/or something I could learn from in terms of automatically generating HTML according to a specific need, without all the needless overhead that seems to accompany the stuff I have been able to find.

So, what I should do is resume my suspended study of Python... or Perl... or...


Thanks.
 
Old 06-04-2005, 12:19 PM   #4
ubergeek42
LQ Newbie
 
Registered: Jun 2005
Distribution: Slackware 11
Posts: 17

Rep: Reputation: 0
Here just create a file with the contents:
Code:
#!/bin/sh
echo "<table><tr>">file.html
counter=0
for i in *.jpg
do
     let "counter++"
     echo "<td><img src=$i></td>">>file.html
     if [ "$counter" -eq 11 ]
     then
          echo "</tr><tr>">>file.html
          counter=0
     fi
done 
echo "</table>">>file.html
Place the file in with your images and run it from the command line. Be sure to chmod +x on it first though.

Last edited by ubergeek42; 06-04-2005 at 12:41 PM.
 
Old 06-04-2005, 11:47 PM   #5
Simon Bridge
Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 197Reputation: 197
ubergeek42: That is a very nice compact bit of scripting there - well done. (It's better than the one I had in mind in fact... and quite saves me the trouble.)

infidel: If this is a personal study - just learn the bash script to start with. All those things you keep doing over and over on the command line, you can create a script for - practise. My peronal order of study is bash - perl - C/C++ but someone says I should be learning java.

note: ubergeek's script includes tricks not in the usual tutorials.
 
Old 06-05-2005, 12:41 AM   #6
shaitand
Member
 
Registered: Jun 2005
Posts: 54

Rep: Reputation: 15
Quote:
Originally posted by ubergeek42
Here just create a file with the contents:
Code:
#!/bin/sh
echo "<table><tr>">file.html
counter=0
for i in *.jpg
do
     let "counter++"
     echo "<td><img src=$i></td>">>file.html
     if [ "$counter" -eq 11 ]
     then
          echo "</tr><tr>">>file.html
          counter=0
     fi
done 
echo "</table>">>file.html
Place the file in with your images and run it from the command line. Be sure to chmod +x on it first though.
That would create 11 columns and 7 rows, to make it 7 rows as the original poster requested simply change:

if [ "$counter" -eq 11 ]

to:

if [ "$counter" -eq 7 ]

Probably does not matter but in case he had something specific in mind.
 
Old 06-05-2005, 12:44 AM   #7
infidel
Member
 
Registered: Jun 2003
Location: Easley, SC, US
Distribution: Ubuntu 7.10, Mandrake 9.2
Posts: 91

Original Poster
Rep: Reputation: 15
Ubergeek42: That is slick, and works like a charm. Thanks!

shaitand: Actually, I caught that after the initial trial. I'm already happily tweaking parameters in the script.

Simon: I've actually been trying to learn a little bash scripting, but with the chaos present in my life at the moment it's been a challenge to study enough to move beyond the "glorified alias" stage. I'll get there, though.

Thanks again.

Last edited by infidel; 06-05-2005 at 12:47 AM.
 
Old 06-05-2005, 12:49 AM   #8
Electro
Guru
 
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
You should include width and height tags as well to reduce the time the browser takes to look up this information. Use identify from ImageMagick to get the width and height information.
 
Old 06-05-2005, 01:07 AM   #9
shaitand
Member
 
Registered: Jun 2005
Posts: 54

Rep: Reputation: 15
*

Last edited by shaitand; 06-05-2005 at 01:54 AM.
 
Old 06-05-2005, 01:32 AM   #10
shaitand
Member
 
Registered: Jun 2005
Posts: 54

Rep: Reputation: 15
Code:
#!/bin/sh
echo "<table><tr>">file.html
counter=0
for i in *.jpg
do
     let "counter++"
     GEOMETRY=`identify $i|perl -e '<>=~/(\d+)x(\d+)/; print "width=\"$1\" height=\"$2\"";'`

     echo "<td><img src=\"$i\" $GEOMETRY></td>">>file.html

     if [ "$counter" -eq 7 ]
     then
          echo "</tr><tr>">>file.html
          counter=0
     fi

done

echo "</table>">>file.html
Scrap my last post, this shortens the perl one liner and properly quotes the width and height values.
It also fixes a missing single quote.

Update: Now includes quotes around image name as well per ubergeeks post.

Last edited by shaitand; 06-05-2005 at 11:07 PM.
 
Old 06-05-2005, 07:27 PM   #11
ubergeek42
LQ Newbie
 
Registered: Jun 2005
Distribution: Slackware 11
Posts: 17

Rep: Reputation: 0
Quote:
Originally posted by Simon Bridge
note: ubergeek's script includes tricks not in the usual tutorials.
Interesting I just learned BASH scripting from a tutorial and that is where all the code came from.
Also i would like to know what is not in the usual tutorials?

Oh BTW that is a nice fix on the code there shaitand. Also since you're adding quotes shouldn't you put some around the image name?

So it ends up like this:
Code:
echo "<td><img src=\"$i\"  $GEOMETRY></td>">>file.html
I'm not up to date on the web standards, so are the quotes even necessary?
 
Old 06-05-2005, 11:16 PM   #12
shaitand
Member
 
Registered: Jun 2005
Posts: 54

Rep: Reputation: 15
Quote:
Originally posted by ubergeek42
I'm not up to date on the web standards, so are the quotes even necessary?
Yes, and no. Yes the quotes are supposed to be there per the standard, but no browser in existance
will flag it, even if your not using quirks mode. I'm not even sure if the W3C html validator
complains (it probably does for xhtml 1.0 since that standard is far less forgiving than html 4.0).
Shortening the perl one liner and fixing the single quote I missed were the main reason for my post.

I'm sure by this time the original poster has already created his table, but if it all the same to you
ubergeek42 I'd like to tuck it back in my collection. The basic function of the script is generic enough
it will probably be useful at some point in the future.
 
Old 06-06-2005, 02:33 AM   #13
Simon Bridge
Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 197Reputation: 197
Quote:
Interesting I just learned BASH scripting from a tutorial and that is where all the code came from.
Really? Cool ... would you post a link to that tutorial for me: it's obviously one I havn't seen.
Quote:
Also I would like to know what is not in the usual tutorials?
... wouldn't we all
 
Old 06-06-2005, 04:06 PM   #14
ubergeek42
LQ Newbie
 
Registered: Jun 2005
Distribution: Slackware 11
Posts: 17

Rep: Reputation: 0
Hmm seems odd that you wouldn't have seen the site, first hit on google for "bash scripting". Everything i used is explained somewhere in that site. But anyways here you go:
http://www.tldp.org/LDP/abs/html/
 
Old 06-07-2005, 02:08 AM   #15
Simon Bridge
Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 197Reputation: 197
Well ... it's been a while Thanx.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why doesnt my simple html post to cgi script work? ginda Linux - Networking 10 03-15-2005 04:32 PM
PHP script to check filetypes and put images into SQL table benrose111488 Programming 5 03-02-2005 02:57 AM
Create custom user's directory with simple script dtournas Programming 2 09-09-2004 06:00 AM
Simple php script with html form not working. sinsoush Programming 4 04-01-2004 09:02 PM
Looking for simple way to create scheduled emails from perl script kdowney Programming 1 10-17-2003 07:32 PM


All times are GMT -5. The time now is 05:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration