Work the Shell - Displaying Image Directories in Apache, Part IV

 in
The final steps in our thumbnail script scale and align the images within a pretty table.
Last Step: Tables for Aligning Things

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!

Figure 1. Example Result from the New Script

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.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

finally

ultramookie's picture

i agree, finally this series is over.

hey dave, on a different note, your example picture kind of shows what kind of stuff you're into, huh?

"hentai-manga-example.gif"?

http://en.wikipedia.org/wiki/Hentai

"[I]n slang situations it often means 'perverted' and is subsequently used in many other countries to refer to anime, manga and computer games with explicit sexual or pornographic content.

"The term "hentai" is also commonly used (outside of Japan) to refer to pornographic animation in general that is not necessarily anime or manga. This is most often the case if the said animation is an imitation of a pre-existing cartoon or character."

finally

etamme's picture

finally this series is over...

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix