Work the Shell - Displaying Image Directories in Apache, Part IV
With all of this tucked into the script, we can use a skeleton table to organize things neatly. In a rough form, it'll look like this:
<table border="0"><tr> <td align="center">image</td> <td align="center">image</td> <td align="center">image</td> </tr></table>
Dropping it into the script, the key block that both displays the image, scaled, and keeps track of when we need to produce a new row in the table is:
if [ $linecount -eq $maxperline ] ; then # new row of table echo "</tr><tr>" linecount=0 fi echo "<td align='center' valign='bottom'>" echo "<a href=$name><img src=$name border=0" echo " alt=$name height=$height width=$width />" echo "<br>$name</a><br>($height x $width)</td>" linecount=$(( $linecount + 1 ))
Now, because I want to write a highly readable script, it's worth highlighting that the top section lets you configure the heck out of this:
maxsize=150 # max thumbnail size, in pixels maxperline=3 # max images per table row
Both of these constants can be tweaked as needed. The result? See Figure 1. Sweet!
The full script is pretty cool. If you'd like to get a copy of it, please pop over to my site: www.intuitive.com/wicked/imagedir.txt. Save it as index.cgi in an image directory on your Web server.
Dave Taylor is a 26-year veteran of UNIX, creator of The Elm Mail System, and most recently author of both the best-selling Wicked Cool Shell Scripts and Teach Yourself Unix in 24 Hours, among his 16 technical books. His main Web site is at www.intuitive.com, and he also offers up tech support at AskDaveTaylor.com.
Dave Taylor has been hacking shell scripts for over thirty years. Really. He's the author of the popular "Wicked Cool Shell Scripts" and can be found on Twitter as @DaveTaylor and more generally at www.DaveTaylorOnline.com.
Win an iPhone 6
Enter to Win
|Geek Hide-away in Guatemala - Stay for Free!||Nov 26, 2015|
|Microsoft and Linux: True Romance or Toxic Love?||Nov 25, 2015|
|Non-Linux FOSS: Install Windows? Yeah, Open Source Can Do That.||Nov 24, 2015|
|Cipher Security: How to harden TLS and SSH||Nov 23, 2015|
|Web Stores Held Hostage||Nov 19, 2015|
|diff -u: What's New in Kernel Development||Nov 17, 2015|
- Microsoft and Linux: True Romance or Toxic Love?
- Cipher Security: How to harden TLS and SSH
- Non-Linux FOSS: Install Windows? Yeah, Open Source Can Do That.
- Web Stores Held Hostage
- Firefox's New Feature for Tighter Security
- Geek Hide-away in Guatemala - Stay for Free!
- It's a Bird. It's Another Bird!
- PuppetLabs Introduces Application Orchestration
- diff -u: What's New in Kernel Development
- IBM LinuxONE Provides New Options for Linux Deployment