[ale] Making JPEG indexes under Linux

Amy Ayers amy.ayers at mindspring.com
Sun Nov 14 10:51:27 EST 1999


This does not seem to modify the files, therefore the
user still has to download the large image files. It
seems only to generate HTML that causes the browser
to display the images as 50x50. What this guy really
wants is MY script. :^) It actually generates thumbnail
image files which are much smaller and also maintains
the aspect ratio so that the thumbnails aren't distorted.

It assumes filenames are *jpg and in the current
directory. This could easily be changed, of course.
I also hardcoded the path of mogrify in the code but
that could be changed too to make it more generic.

Perhaps the default maximum size which I hardcoded
in there (128x128) should also be a command line option.
Other improvements are likely since I'm no perl expert,
but this does what I need it to do.

-Amy

-----------------------------------------------------------------

#!/usr/bin/perl

$title = "Annie visits SciTrek, plays, sleeps, etc : 7/23/1999 -
8/7/1999";
$bgcolor = "\"#FFFFdd\"";
$textcolor = "\"#dd0000\"";


@files = split(' ',`/bin/ls *jpg`);

$indexfile = "index.html";
open (INDEX, ">$indexfile");

print INDEX <<EOHTML;

</pre>
<html>
<head>
<title>$title</title>
</head>

<body bgcolor=$bgcolor text=$textcolor>
<h1 align=center>$title</h1>
<center>
<table cellpadding=3>
<tr>

EOHTML

$count = 0;

foreach $file (@files) {

        print INDEX "\<td align=center valign=center\>";

        $_ = $file;
        /(.*)\.jpg/;
        $fileroot = $1;

        `/bin/cp $file $fileroot'.small.jpg'`;
        `/usr/X11R6/bin/mogrify -geometry 128x128
$fileroot'.small.jpg'`;

        $id = `/usr/X11R6/bin/identify $fileroot'.small.jpg'`;
        $_ = $id;
        /[A-Za-z0-9\.\-\_]*\s([0-9]*)x([0-9]*)\s.*/;
        $width=$1;
        $height=$2;

        print INDEX "\<a href=\"$file\"\>\<img width=$width
height=$height src=\
"$fileroot.small.jpg\"\>\</a\>\n";

        print INDEX "\</td\>\n";

        if ($count == 3) {
                print INDEX "\</tr\>\n\<tr\>";
                $count = 0;
        }
        else {
                $count++;
        }

}

print INDEX <<EOHTML;

</tr>
</table>
</center>
</body>
</html>
<pre>

EOHTML


-------------------------------------------------------------------------


Pete Hardie wrote:
> 
> Thompson Freeman wrote:
> >
> > I recently obtained one of the Sony Mavecia cameras which stores the
> > pictures as *jpg files on floppies, and have run into a slight challenge
> > which I didn't forsee. Under Linux, is there a _simple_ way to create an
> > index/contact sheet/thumbnail sheet (I'm not even sure what they are
> > called!) from stored JPEGs?
> 
> Attached is a short shell script that creates and HTML file of thumbnails.
> It does not correctly size them, but I'm sure that a quick look at the
> JPEG format would reveal the section that saves the dimensions of the image,
> which could be added to this.
> 
> --
> Pete Hardie                   |   Goalie, DVSG Dart Team
> Scientific Atlanta            |
> Digital Video Services Group  |
> 
>   ------------------------------------------------------------------------
>                     Name: image_html.sh
>    image_html.sh    Type: Bourne Shell Program (application/x-sh)
>                 Encoding: 7bit






More information about the Ale mailing list