#!/usr/local/bin/perl -w # # imagedir.lc # # This file implements a few functions which are useful # to create index files for photos. The primary functions # are: # ListSubdirectories List all subdirectories # ShowThumbnails Show all .t. or .m. photos # use strict; ### ### ListSubdirectories ### ### Find all of the subdirectories descending from this ### directory which have index.wc files in them. When found, ### extract the _TITLE_ to build a meaningful title. ### sub ListSubdirectories { local($/); my($data, $file, @files, $title); print OUT "\n"; # Set permissions # system(qq|find . -type d -exec chmod 755 {} \\;|); # system(qq|find . -type f -name "*.jpg" -exec chmod 644 {} \\;|); } ### ### ShowThumbnails ### ### Find all of the thumbnail images, and create an appropriate ### link to the "real" image. The real image can be the basename ### with ".html", or the full sized image. ### sub ShowThumbnails { my(%basename, $file, @files, $href, $img); opendir(DIR, ".") || die "Cannot open directory: $!"; @files = sort(readdir(DIR)); closedir DIR; # Find the basenames of all image files. for $file (@files) { next unless ($file =~ /(.*?)((\.[tm])*)\.(jpg|jpeg|gif|png)$/); $basename{$1} = $4; } # For each of the basenames, generate the appropriate thumbnail # and the appropriate reference to the "real" image. for $file (sort keys %basename) { # Find the "real" file. if (-f "$file.html") { $href = "$file.html"; } elsif (-f "$file.$basename{$file}") { $href = "$file.$basename{$file}"; } else { $href = "$file.jpg"; # Punt print STDERR "Cannot find a file to link to for $file\n"; } # Find the appropriate thumbnail file. if (-f "$file.t.$basename{$file}") { $img = "$file.t.$basename{$file}"; } elsif (-f "$file.m.$basename{$file}") { $img = "$file.m.$basename{$file}"; } elsif (-f "$file.$basename{$file}") { $img = "$file.$basename{$file}"; } else { $img = "$file.jpg"; # Punt print STDERR "Cannot find a thumbnail for $file\n"; } # Generate a reference print OUT qq|\n|; } } 1;