#!/usr/bin/perl # yathumb.pl - Simple web thumbnail page creator # Project homepage: http://www.landrop.com/yathumb.html # # 0.0.6: added html page for each image containing prev/index/next links (July 2003) # 0.0.5: added command line options: # 0.0.4: added ability to use either .html or .php # 0.0.3: added footer option (internal version) (Only works with php) # 0.0.2: added in check for ImageMagick version (internal version) # 0.0.1: 1st release, April 20 2002 # 18 May 2002: Rename Project to yathumb.pl # 16 Apr 2002: Begin working on gthumb.pl, using genethumb.sh as a guide # # # The genethumb.sh project can be found at http://sam.zoy.org/projects/unix/genethumb.html # there is also a freshmeat.net page for genethumb.sh # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # use Cwd; use File::Basename; use Getopt::Long qw(:config no_auto_abbrev); $version="0.0.6"; $THFILE="index.html"; # if your site has php, and want a nicer looking page, change to index.php $THDIR="."; # put thumbnails in current dir by default $THEXT="jpg"; # change this to png or whatever you want $THWIDTH=96; # thumbnail width $THHEIGHT=72; # thumbnail height $THCOLS=4; # change to set table width -- 0 for no tables $WIDTH=800; # image width $HEIGHT=600; # image height $HEADER="http://www.example.com/head.inc"; # your sites header file. (only active with index.php) $imgHEADER=$HEADER; $FOOTER=' '; # your sites footer file (if you want a footer file add it here, only works with php) $imgFOOTER=$FOOTER; $loop=0; # Version check imagemagick ($temp)=split(' ', `identify -help | cut -d ' ' -f 3 -s`); ($temp)=split('\.', $temp); if ( $temp == 4 ) { $RESPOS=1; $SIZPOS=3; } else { $RESPOS=2; $SIZPOS=5; } #process the command line my $html = ''; my $cols = ''; my $help = ''; GetOptions ( 'html' => \$html, 'cols|c:i' => \$cols, 'width=i' => \$WIDTH, 'height=i' => \$HEIGT, 'help' => \$help); if($cols > 0) { $THCOLS=$cols; } if($html == 1){ $THFILE="index.html"; } # check if index exists, if so, back it up if ( -e "$THFILE" ) { system("mv", "$THFILE", "$THFILE.bak"); } # Check if the thumb nail dir exists, if not create it if ( !-e $THDIR ) { system("mkdir", $THDIR); } open (FILE, ">$THFILE") || die "Could not write to $file\n"; if ( $THFILE ne 'index.html' ) { print FILE "<\?php\ \$cwd=exec(\"pwd\")\;\ \$title=basename(\$cwd)\;\ include(\"$HEADER\")\;\ \?>"; } else { $temp = basename(getcwd); print FILE "\ $temp\

$temp

\ \ \ "; } print FILE "\ \n"; # Read in the file names to an array # exclude: # files that begin with . # files that begin with tn_ # files that don't end with .jpg opendir(DIR,"."); while($file = readdir(DIR)){ next if ($file =~ /^tn_/i); next if ($file =~ /^\./); next if ($file =~ /$\.html/i); next if ($file =~ /$\.php/i); next if ($file !~ /$\.jpg/i); $files[$loop]=$file; $loop++; } close(DIR); # Sort the array by name, case insensitive (bubble sort, wohoo) for($i=0; $i<$loop-1; $i++) { for($j=0; $j<($loop-1-$i); $j++) { if(lc($files[$j+1]) lt lc($files[$j])) # compare two neighbours { $temp=$files[$j]; # swap them $files[$j]=$files[$j+1]; $files[$j+1]=$temp; } #End of if } # end of inner for loop } $column=0; $ie=0; foreach $FileName (@files) { # -------------------------------------------------------# # begin section to add html page per pic # # -------------------------------------------------------# $fff=1; if ( $THFILE ne 'index.html' ) { $EXT=".php"; open (FILE2, ">$FileName$EXT") || die "Could not write to $file\n"; if ($imgHEADER ne ' ') { print FILE2 "<\?php\ include(\"$imgHEADER\")\;\ \?>\n"; } } else { $EXT=".html"; open (FILE2, ">$FileName$EXT") || die "Could not write to $file\n"; print FILE2 "\<\!DOCTYPE html PUBLIC \"\-//W3C//DTD HTML 4.01 Transitional//EN\"\>\n"; } if ( $ie == 0 ) { print FILE2 "\ previous \| \index\ \| \next\\"; $fff=0; } if ( $ie == $loop-1 ) { print FILE2 "\ \previous\ \| \index\ \| next\"; $fff=0; } if ( $fff == 1 ) { print FILE2 "\ \previous\ \| \index\ \| \next\\"; } print FILE2 "\n\\"$FileName\"\\n"; if ( $THFILE ne 'index.html' ) { print FILE2 "
"; if ($imgFOOTER ne ' ') { print FILE2 "\n
\n"; print FILE2"<\?php\ include(\"$imgFOOTER\")\;\ \?>"; } } close(FILE2); $ie=$ie+1; # -------------------------------------------------------# # end of the 'html page per pic section # # -------------------------------------------------------# print "$FileName..."; $column++; (@geom) = split(' ', `identify $FileName`); ($width, $height) = split('x', $geom[$RESPOS]); if ( !-e "tn_$FileName" ) { `convert -geometry ${THWIDTH}x${THHEIGHT} $FileName "tn_$FileName"`; } (@geomth) = split(' ', `identify tn_$FileName`); ($widthth, $heightth) = split('x', $geomth[$RESPOS]); if ( $width > $height ) { if ( $width > $WIDTH ) { `mogrify -geometry ""$WIDTH"x"$HEIGHT">" $FileName`; } } else { if ($width > $HEIGHT ) { `mogrify -geometry ""$HEIGHT"x"$WIDTH">" $FileName`; } } (@geom) = split(' ', `identify $FileName`); ($width, $height) = split('x', $geom[$RESPOS]); $TruncName=substr $FileName, 0, 20; if ( $FileName ne $TruncName ) { $TruncName= (substr $FileName, 0 , 17) . "..."; } print FILE "
\n"; if ($column == $THCOLS ) { print FILE " "; $column=0; } print"Done\n"; } print FILE " \
\ \"$FileName
$TruncName
$geom[$SIZPOS]
$geom[$RESPOS]
\


\ generated by
yathumb.pl version $version\

\ "; if ($FOOTER ne ' ') { print FILE"<\?php\ include(\"$FOOTER\")\;\ \?>"; } close(FILE);