Creates an HTML image catalog/gallery from image files. Recursively finds images (PCX, BMP, GIF, JPG, JPEG, PSD, TIF, TIFF), generates thumbnails using alchlong.exe, and creates an organized HTML index with image thumbnails, file sizes, and directory structure. Includes progress tracking and time estimation. Created for ReklamaFactor in 2007.
perl makealbum.pl <input_directory> <output_directory>
Scans input directory for images, generates thumbnails, and creates an HTML catalog in the output directory.
#!/usr/bin/perl
#
sub tree {
my(@filenames);
local (*ROOT);
my($root) = $_[0];
opendir ROOT, $root;
my(@filelist) = readdir ROOT;
closedir ROOT;
foreach $name (@filelist) {
if ($name ne '.' and $name ne '..') {
$name = $root . "\\" . $name;
if (-f $name && ($name =~ /.pcx$|.bmp$|.gif$|.jpg$|.jpeg$|.psd$|.tif$|.tiff$/i)) {
$name =~ s/\\\\/\\/;
@filenames = (@filenames, $name);
$filesizes{$name} = (stat($name))[7];
$sizea += $filesizes{$name};
$i++;
}
@filenames = (@filenames, tree($name)) if (-d $name);
}
}
print "$i images ($sizea bytes): $root\n";
return @filenames;
}
$outdir = $ARGV[1] or die "outdir fail...";
@filenames = tree($ARGV[0]) or die "indir fail...";;
system("md \"$outdir\"") if (!-d $outdir);
open(CATALOG, ">$outdir\\index.html") or die "index fail...";
print CATALOG <<EOF;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<title>ReklamaFactor image catalog [$ARGV[0]]</title>
<style type="text/css">
<!--
body,td,th {
font-family: Arial, Helvetica, sans-serif;
font-size: 10pt;
color: #666666;
}
td {
background-color: #CCCCCC;
font-size: 8pt;
}
th {
font-family: Arial, Helvetica, sans-serif;
font-size: 10pt;
color: #FFFFFF;
background-color: #224488;
}
a:link {
color: #0099FF;
}
a:visited {
color: #990033;
}
a:hover {
color: #FF0000;
}
a:active {
color: #0000FF;
}
-->
</style>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="5" cellspacing="3">
EOF
$t1 = time;
foreach $filename (@filenames) {
($name, @path) = reverse(split(/\\/, $filename));
($drive, @outpath) = reverse(@path);
$outpath = join("\\", @outpath);
if ($lastoutpath ne $outpath) {
if ($n%4 != 0){
while ($n%4 != 0) {
print CATALOG "<td> </td>\n";
$n++;
}
print CATALOG "</tr>\n";
}
print CATALOG "<tr><th colspan=4 align=center>$drive\\$outpath</th></tr>\n";
$lastoutpath = $outpath;
}
system("md \"$outdir\\$outpath\"") if (!-d "$outdir\\$outpath");
system("alchlong.exe \"$filename\" \"$outdir\\$outpath\\$name.jpg\" -Xd200 -Yd200 -+ -jh") if (!-f "$outdir\\$outpath\\$name.jpg");
print CATALOG "<tr>\n" if ($n%4 == 0);
print CATALOG "<td align=center><a href=\"$filename\"><image border=0 src='$outpath\\$name.jpg' alt='$name.jpg'></a><br>\n";
print CATALOG "<a href=\"$filename\">$name ($filesizes{$filename} bytes)</a></td>\n";
print CATALOG "</tr>\n" if (($n+1)%4 == 0);
$n++;
$i--;
$sizea -= $filesizes{$filename};
$sizeb += $filesizes{$filename};
$tl = (time - $t1) * ($sizea / $sizeb + $i / $n) / 2;
($tlt{'h'}) = split(/\./, ($tl/3600)%24);
($tlt{'m'}) = split(/\./, ($tl/60)%60);
($tlt{'s'}) = split(/\./, ($tl/1)%60);
print "$i images ($sizea bytes and $tlt{'h'}:$tlt{'m'}:$tlt{'s'}) left...\n";
}
if ($n%4 != 0){
while ($n%4 != 0) {
print CATALOG "<td> </td>\n";
$n++;
}
}
print CATALOG <<EOF;
</table>
<p align="center">© ReklamaFactor 2007<br>© <a href="https://kusaku.su/" title="made by kusaku" target="_blank">kusaku</a> 2007</p>
</body>
</html>
EOF