All pastes #35488 Raw Edit

Mine

public text v1 · immutable
#35488 ·published 2006-01-02 03:50 UTC
rendered paste body
The script: MakeWebPageIndexUsingThumbnails

#!/usr/bin/perl

# Script:       MakeWebPageIndexUsingThumbnails

# Description:  Create html to display all graphics on the system
#
# Author:       Brant L. Pellett, with minor revisions by Dennis Carr
# Version:      1.3.1
# Date:         09-Mar-2002
# Copyright:    Copyright (C) 1997-2002 Brant Pellett, Dennis Carr
#               Permission granted to copy freely on a strictly cost-free basis\
.
# Note - this revision expects you to have a file called ".index" in the
# directory you run it in.  This will contain something that will read as
# "<foo> Image Archive" at the top of the page.  If the file is not in the
# directory, your page is simply titled "image archive".
#
# 1.3.1 implemented a minor change in tabling for the NextPrev routine, correct\
ing
# some tabling issues that existed.
#
# Plans to make it default to the directory name for lack of a .index file
# are dormant.

#       C O N F I G U R A T I O N   S E C T I O N :
$ImagesPerPage = 28 ;
$TableWidth = "4" ;

#       C O N S T A N T S :
#$TempFile="/tmp/MakeWebPageIndexUsingThumbnails-" . $$ ;
$ThisDir=`cat ./.index` ; chop ($ThisDir) ;

$DoubleQuote = '"' ;

#       Get list of files:


 open (IN,"find " . join(" ",@ARGV) . " -type d -o -print | sort |");

 while ( $SomeFile = <IN> )
 {
 #     Ignore thumbnails:
       if      ( $SomeFile =~ m/\// )
       {
               @FileNameParts = split("/",$SomeFile) ;
               $SomeBasename = pop(@FileNameParts) ;
       }
       else
       {
               $SomeBasename = $SomeFile ;
       } ;

       if      ( $SomeBasename =~ m/^tn_/ )
       {
               next ;
       } ;


        chop($SomeFile);
        study($SomeFile);
        if      (       ( $SomeFile =~ m/\.gif$/i ) ||
                        ( $SomeFile =~ m/\.jpg$/i ) ||
                        ( $SomeFile =~ m/\.jpeg$/i )    )
        {
                if      ( -f $SomeFile )
                {
                        push(@GraphicFiles, $SomeFile) ;
dprint("Found:\t" . $SomeFile . "\n") ;
                };
        } ;
};
close(IN);

$GraphicFileCount = scalar ( @GraphicFiles ) ;
dprint("Total Graphic Files Found:\t" . $GraphicFileCount . "\n") ;
while   ( 0 != ($GraphicFileCount % $TableWidth ) )
{
        push(@GraphicFiles, " ") ;
        $GraphicFileCount = scalar ( @GraphicFiles ) ;
} ;

$GraphicFileCount = scalar ( @GraphicFiles ) ;
#$EstimatedNumberOfPages = $GraphicFileCount / $ImagesPerPage ;
$EstimatedNumberOfPages = int ($GraphicFileCount / $ImagesPerPage ) ;
if      ( $GraphicFileCount % $ImagesPerPage )  { $EstimatedNumberOfPages++ } ;


if      ( $EstimatedNumberOfPages < 100 )       { $PageNumberFormat = "%2.2d" ;\
 }
elsif   ( $EstimatedNumberOfPages < 1000 )      { $PageNumberFormat = "%3.3d" ;\
 }
elsif   ( $EstimatedNumberOfPages < 10000 )     { $PageNumberFormat = "%4.4d" ;\
 }
elsif   ( $EstimatedNumberOfPages < 100000 )    { $PageNumberFormat = "%5.5d" ;\
 }
else                                            { $PageNumberFormat = "%9.9d" ;\
 } ;

$PageCounter = 0 ;
while   ( $GraphicFileCount > 0 )
{
        $PageFileName = sprintf($PageNumberFormat,$PageCounter) . "-ImageIndex.\
html" ;
        open (OUT,">" . $PageFileName) || die("Out:" . $PageFileName) ;
        print (OUT "<HTML>\n");
        print (OUT "<HEADER>\n") ;
        print (OUT "<meta http-equiv=\"Content-Type\" content=\"text/html; char\
set=iso-8859-1\">\n") ;
        print (OUT "<TITLE>\n") ;
        if      ( $EstimatedNumberOfPages < 2 )
        {
                print (OUT "\t\t\t" . $ThisDir . " Image Archive\n") ;
        }
        else
        {
                print (OUT "\t\t\t" . $ThisDir . " Image Archive, Page " .
                        sprintf($PageNumberFormat,$PageCounter) . "\n") ;
        } ;
        print (OUT "</TITLE>\n") ;
        print (OUT "</HEADER>\n") ;
        print (OUT "<BODY TEXT=\"#FFFFFF\" BGCOLOR=\"#000000\" LINK=\"#66FFFF\"\
 VLINK=\"#CCCCCC\" ALINK=\"#FFCC99\">\n") ;
        print (OUT "<H1>\n") ;
        print (OUT "<div align=right><font size=+2>" . $ThisDir . " Image Archi\
ve, Page " .
                sprintf($PageNumberFormat,$PageCounter) . "\n </font>") ;
        print (OUT "<br><font size=+2>The northarc.com image archive</font></di\
v>\n") ;
        print (OUT "\n<hr WIDTH=\"100%\".\n") ;
        print (OUT "\n<br>\n") ;
        print (OUT "<table BORDER COLS=2 WIDTH=\"100%\">\n");
        print (OUT "<tr>\n");
        print (OUT "<p><td WIDTH=\"10%\"><img SRC=\"http://www.northarc.com/~ke\
6isf/YOURHERE.jpg\" height=25 width=125></td>\n");
        print (OUT "<td BGCOLOR=\"#808080\"><A HREF=\"http://www.northarc.com/~\
ke6isf\">Sunset Grill: Home</a> -> <a href=\"http://www.northarc.com/images/ani\
me-images.html\">Anime Image Archives</a> -> ".$ThisDir." page ".sprintf($PageN\
umberFormat,$PageCounter) . "\n");
        print (OUT "</tr></table>\n\n");

        print (OUT "</H1>\n") ;
        print (OUT "<H2>\n");
        print (OUT "<TABLE>\n");
        print (OUT "<TR>\n");

        $ColumnCount = "0" ;
        $FirstTime = "True" ;
        #foreach $aGraphicFile ( sort @GraphicFiles )
#       foreach $aGraphicFile ( @GraphicFiles )

        $ImageCounter = 0 ;
#       Keep going as long as both: 1) the page is not yet full, and 2) there a\
re more graphics:
        while   (       ( $ImageCounter < $ImagesPerPage ) && ( scalar(@Graphic\
Files) > 0 ) )
        {
                $aGraphicFile = shift( @GraphicFiles ) ;

                if      ( -f $aGraphicFile )
                {
                        $ColumnCount++ ;

                        if      ( $ColumnCount > $TableWidth )
                        {
                                print (OUT "</TR>\n");
                                print (OUT "<TR>\n");
                                $ColumnCount = "1" ;
                        } ;

                        $ThumbnailFileName = "tn_" . $aGraphicFile ;
                        $ThumbnailFileName =~ s/tn_.\//.\/tn_/ ;
                        if      ( $TableWidth == 3 )
                        {
                                $ThumbnailWidth = 240 ;
                                $ThumbnailHeigth = 180 ;
                        }
                        elsif   ( $TableWidth == 4 )
                        {
                                $ThumbnailWidth = 120 ;
                                $ThumbnailHeigth = 90 ;
                        }
                        elsif   ( $TableWidth == 5 )
                        {
                                $ThumbnailWidth = 150 ;
                                $ThumbnailHeigth = 100 ;
                        }
                        else
                        {   
                                $ThumbnailWidth = 150 ;
                                $ThumbnailHeigth = 100 ;
                        } ;

                        print (OUT "<TD>\n");
                        print (OUT "<A HREF=" .
                                $DoubleQuote .  $aGraphicFile . $DoubleQuote .
                                "><IMG SRC=" .
                                $DoubleQuote . $ThumbnailFileName . $DoubleQuot\
e .
                                " width=" . $DoubleQuote . $ThumbnailWidth . $D\
oubleQuote .
                                " heigth=" . $DoubleQuote . $ThumbnailHeigth . \
$DoubleQuote .
                                "></A>\n");
                        print (OUT "</TD>\n");
                };
                $ImageCounter++ ;
        };
        print (OUT "</TR>\n");
        print (OUT "</TABLE>\n");
        print (OUT "<hr>\n");
        &NextPrev;
        print (OUT "<p><hr><p><center></font><font size=-1>This collection comp\
iled by <a href=\"http://www.northarc.com/~ke6isf/contact\">Dennis Carr</a></ce\
nter>\n");
        print (OUT "</H2>\n");
#       print (OUT "<HR>\n") ;
        print (OUT "</BODY>\n");
        print (OUT "</HTML>\n");
        close(OUT);

        $PageCounter++ ;
        $GraphicFileCount = scalar ( @GraphicFiles ) ;
};

#       Debug printer - comment out print() to turn off debugging:
sub dprint
{
        print(join(" ",@_)) ;
} ;

#       Next/Previous subroutine - inserts guides at the end of table

sub NextPrev
{
$PrevFileName = sprintf($PageNumberFormat,$PageCounter-1) . "-ImageIndex.html" \
;
$NextFileName = sprintf($PageNumberFormat,$PageCounter+1) . "-ImageIndex.html" \
;
$LastPage = $EstimatedNumberOfPages-1;

if ($EstimatedNumberOfPages > 1)
{
        print (OUT "<TABLE cols=4 width=\"100%\">\n");
        print (OUT "<TR>\n");
        print (OUT "<TD width=\"25%\">\n");

       if ($PageCounter > 0)
        {
                        print (OUT "<A HREF=" .
                                $DoubleQuote .  $PrevFileName . $DoubleQuote .
                                "><center><font size=+2>Previous</font></center\
></a>\n");
                }
        print (OUT " </TD>\n");
        print (OUT "<TD width=\"50%\">\n</TD>");
        print (OUT "<TD width=\"25%\"> \n");

        if ($PageCounter < $LastPage)
                {
                        print (OUT "<A HREF=" .
                                $DoubleQuote .  $NextFileName . $DoubleQuote .
                                "><font size=+2><center>Next</center></font></A\
>\n");
                        print (OUT "</TD>\n");
                }
        print (OUT "</TR></TABLE>\n");
}}

[EOF]


Results of perl -V:

Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.4.21-1.1931.2.382.entsmp, archname=i386-linux-thread\
-multi
    uname='linux str'
    config_args='-des -Doptimize=-O2 -g -pipe -march=i386 -mcpu=i686 -Dmyhostna\
me=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstal\
lprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Dvendorprefix=/usr -Dsitepref\
ix=/usr -Dotherlibdirs=/usr/lib/perl5/5.8.0 -Duseshrplib -Dusethreads -Duseithr\
eads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_s\
hadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl -Ubincompat5005 \
-Uversiononly -Dpager=/usr/bin/less -isr'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef'
 useithreads=define usemultiplicity=
    useperlio= d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=un uselongdouble=
    usemymalloc=, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGG\
ING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSE\
T_BITS=64 -I/usr/include/gdbm',
    optimize='',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-s\
trict-aliasing -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='3.2.2 20030222 (Red Hat Linux 3.2.2-5)', gccosand\
vers=''
gccversion='3.2.2 200302'
    intsize=r, longsize=r, ptrsize=5, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long'
k', ivsize=4'
ivtype='l, nvtype='double'
o_nonbl', nvsize=, Off_t='', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc'
l', ldflags =' -L/u'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lpthread -lc -lcrypt -lutil
    perllibs=
    libc=/lib/libc-2.3.2.so, so=so, useshrplib=true, libperl=libper
    gnulibc_version='2.3.2'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so', d_dlsymun=undef, ccdlflags='-rdynamic -Wl,-r\
path,/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE'
    cccdlflags='-fPIC'
ccdlflags='-rdynamic -Wl,-rpath,/usr/lib/perl5', lddlflags='s Unicode/Normalize\
 XS/A'


Characteristics of this binary (from libperl):
  Compile-time options: DEBUGGING MULTIPLICITY USE_ITHREADS USE_LARGE_FILES PER\
L_IMPLICIT_CONTEXT
  Locally applied patches:
        MAINT18379
  Built under linux
  Compiled at Aug 13 2003 11:47:58
  @INC:
    /usr/lib/perl5/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/5.8.0
    /usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.0
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.0
    /usr/lib/perl5/vendor_perl
    /usr/lib/perl5/5.8.0/i386-linux-thread-multi
    /usr/lib/perl5/5.8.0