#!/usr/bin/perl -w # vim: set sw=4 ts=4 si et: # Copyright: GPL, Author: Guido Socher # For instructions see: sub help() # Uses ImageMagick convert program: # convert -geometry 450x450 image t_image # use strict; use vars qw($opt_f $opt_h); use Getopt::Std; my %html; my %file2htmlpage; my @files; my @pages; my %pages2title; my $title=""; my $file=""; my $tfile=""; my $ttfile=""; my $tdir=""; my $txt=""; my $name=""; my $today; my $ver="0.3"; # my $imageperpage=0; my $pagecnt=0; $today=&today(); &readHTMLpage; # &getopts("fh")||die "ERROR: No such option. -h for help\n"; &help if ($opt_h); # &help unless($ARGV[0]); # The processing takes long time and it causes problems if # the textfile is modified during that time. Therefore we read it at # once: my @textfile; open(FF,"$ARGV[0]")||die "ERROR: can not read file $ARGV[0]\n"; while(){ next if (/^\s*\#/); push(@textfile,$_); } close FF; foreach (@textfile){ next unless (/\w/); if (/^== *(.+)/){ $title=$1; # if we have already images on the current page then we close that # page if ($imageperpage){ &printHTMLpage('tail'); close OUT; $pagecnt++; $imageperpage=0; } next; } if (/^(\S+)\s*(.*)/){ if ($2){ $txt=$2; &htmlumlaute(\$txt); }else{ $txt=""; } $file=$1; # make realative file name: $file=~s/^\.\///; unless(-r "$file"){ print STDERR "Warning: line $., can not read image $file, ignoring it\n"; next; } if (-d "$file"){ print STDERR "Warning: line $., $file is a directory, ignoring it\n"; next; } if($file=~/_tt?\./){ print STDERR "Warning: line $. : $file looks like a thumb nail, ignoring it\n"; next; } unless($file=~/(\.jpg)|(\.gif)/i){ print STDERR "Warning: line $. : $file is not jpg or gif, ignoring it\n"; next; } # ($tfile,$tdir)=&tfile($file); ($ttfile,$tdir)=&ttfile($file); unless (-d "$tdir"){ print "making directory $tdir\n"; system("mkdir -p $tdir"); } $name=$file; $name=~s/\W/_/g; if ($imageperpage==0){ #first image open(OUT,">index_$pagecnt.html")||die "ERROR: can not write index_$pagecnt.html\n"; push(@pages,"index_$pagecnt.html"); if ($title){ $pages2title{"index_$pagecnt.html"}=$title; }else{ $pages2title{"index_$pagecnt.html"}="index_$pagecnt.html"; } &printHTMLpage('head'); } &printHTMLpage('thumbstart'); &printHTMLpage('thumbstop'); $imageperpage++; $file2htmlpage{$file}="index_$pagecnt.html#$name"; push(@files,"$file"); print STDOUT "$file\n"; if (! -f "$tfile" || $opt_f){ system("convert -geometry \"560x420>\" $file $tfile"); # you can otherwise not crtl-c the program: sleep 1; } if (! -f "$ttfile" || $opt_f){ system("convert -geometry 50x50 $file $ttfile"); # you can otherwise not crtl-c the program: sleep 1; } } } if($imageperpage){ &printHTMLpage('tail'); close OUT; } my $all=0; my $i=0; for $file (@files){ if ($i==0){ open(OUT,">index_all$all.html")||die "ERROR: can not write index_all$all.html\n"; &printHTMLpage('thumbonlyhead'); print OUT "\n"; print OUT "\n"; } $i++; ($ttfile,$tdir)=&ttfile($file); print OUT " "; if ($i % 5 == 0){ print OUT "\n\n"; } if ($i == 50 ){ $all++; print OUT "\n\n
\n"; print OUT "

Next page

\n"; &printHTMLpage('thumbonlytail'); close OUT; $i=0; } } if ($i){ print OUT "\n\n\n"; &printHTMLpage('thumbonlytail'); close OUT; } # # content page if ($pagecnt){ open(OUT,">index.html")||die "ERROR: can not write index.html\n"; $title="Picture index"; &printHTMLpage('contenthead'); for $file (@pages){ $tfile=$pages2title{$file}; print OUT "
$tfile\n"; } &printHTMLpage('contenttail'); close OUT; }else{ system("cp index_0.html index.html"); } system("cp index.html index.htm"); #-------------------------------------------------------- sub printHTMLpage($){ my $reqpage = shift; my $t; die "ERROR: no such template $reqpage\n" unless ($html{$reqpage}); for (@{$html{$reqpage}}){ # must copy otherwise we change %html $t=$_; $t=~s/\$title/$title/; $t=~s/\$file/$file/g; $t=~s/\$tfile/$tfile/; $t=~s/\$ttfile/$ttfile/; $t=~s/\$name/$name/; $t=~s/\$txt/$txt/; $t=~s/\$today/$today/; $t=~s/\$ver/$ver/; print OUT $t; } } #-------------------------------------------------------- sub readHTMLpage(){ #read and print any text between __ xxx __ and the next __ my $pagename="nix"; while(){ if (/^__ (\w+) __/){ $pagename=$1; next; } next if (/^__ /); push(@{$html{$pagename}},$_); } } #-------------------------------------------------------- sub dirname($){ my $file=shift; if ($file=~/\//){ $file=~s/\/.*$//; return($file); }else{ return "."; } } #-------------------------------------------------------- sub basename($){ my $file=shift; $file=~s/^.*\///; $file; } #-------------------------------------------------------- # convert the file name xxx/yyy/zzz.jpg into xxx/yyy/zzz_t.jpg sub tfile($){ my $file=shift; my ($b,$d); $b=&basename($file); $b=~s/(\.\w+)$/_t$1/; $d=&dirname($file); ("thumbs/$d/$b","thumbs/$d"); } #-------------------------------------------------------- # convert the file name xxx/yyy/zzz.jpg into xxx/yyy/zzz_tt.jpg sub ttfile($){ my $file=shift; my ($b,$d); $b=&basename($file); $b=~s/(\.\w+)$/_tt$1/; $d=&dirname($file); ("thumbs/$d/$b","thumbs/$d"); } #-------------------------------------------------------- sub today{ my @ltime = gmtime; my $today; $today = sprintf("%04d-%02d-%02d",1900 + $ltime[5],$ltime[4] + 1,$ltime[3]); $today; } #-------------------------------------------------------- sub htmlumlaute($){ my $txt_ptr=shift; $$txt_ptr=~s/¡/\¡/g; $$txt_ptr=~s/¿/\¿/g; $$txt_ptr=~s/À/\À/g; $$txt_ptr=~s/Á/\Á/g; $$txt_ptr=~s/Â/\Â/g; $$txt_ptr=~s/Ã/\Ã/g; $$txt_ptr=~s/Ä/\Ä/g; $$txt_ptr=~s/Å/\Å/g; $$txt_ptr=~s/Ç/\Ç/g; $$txt_ptr=~s/È/\È/g; $$txt_ptr=~s/É/\É/g; $$txt_ptr=~s/Ê/\Ê/g; $$txt_ptr=~s/Ë/\Ë/g; $$txt_ptr=~s/Ì/\Ì/g; $$txt_ptr=~s/Í/\Í/g; $$txt_ptr=~s/Î/\Î/g; $$txt_ptr=~s/Ï/\Ï/g; $$txt_ptr=~s/Ñ/\Ñ/g; $$txt_ptr=~s/Ò/\Ò/g; $$txt_ptr=~s/Ó/\Ó/g; $$txt_ptr=~s/Ô/\Ô/g; $$txt_ptr=~s/Õ/\Õ/g; $$txt_ptr=~s/Ö/\Ö/g; $$txt_ptr=~s/Ø/\Ø/g; $$txt_ptr=~s/Ù/\Ù/g; $$txt_ptr=~s/Ú/\Ú/g; $$txt_ptr=~s/Û/\Û/g; $$txt_ptr=~s/Ü/\Ü/g; $$txt_ptr=~s/Ý/\Ý/g; $$txt_ptr=~s/ß/\ß/g; $$txt_ptr=~s/à/\à/g; $$txt_ptr=~s/á/\á/g; $$txt_ptr=~s/â/\â/g; $$txt_ptr=~s/ã/\ã/g; $$txt_ptr=~s/ä/\ä/g; $$txt_ptr=~s/å/\å/g; $$txt_ptr=~s/æ/\æ/g; $$txt_ptr=~s/ç/\ç/g; $$txt_ptr=~s/è/\è/g; $$txt_ptr=~s/é/\é/g; $$txt_ptr=~s/ê/\ê/g; $$txt_ptr=~s/ë/\ë/g; $$txt_ptr=~s/ì/\ì/g; $$txt_ptr=~s/í/\í/g; $$txt_ptr=~s/î/\î/g; $$txt_ptr=~s/ñ/\ñ/g; $$txt_ptr=~s/ò/\ò/g; $$txt_ptr=~s/ó/\ó/g; $$txt_ptr=~s/ô/\ô/g; $$txt_ptr=~s/ö/\ö/g; $$txt_ptr=~s/ù/\ù/g; $$txt_ptr=~s/ú/\ú/g; $$txt_ptr=~s/û/\û/g; $$txt_ptr=~s/ü/\ü/g; } #-------------------------------------------------------- sub help{ print "htmlpictures -- make a nice webpage with images USAGE: htmlpictures [-hf] text-file The text file contains a list of the images. This list can e.g be generated with find . -print > text-file The text file has to have the following syntax: filename optinal textual description == title filename2 optinal textual description ... The textual description will appear besides the image on the webpage. The line == title starts a new webpage for all following images and give the webpage the specified title. OPTIONS: -h this help -f force generation of thumb images even if they already exist (normally images are not regenerated when you run it a second time) \n"; exit; } #-------------------------------------------------------- __END__ __ thumbonlytail __ __ thumbonlyhead __ total index of all images
content Go to total picture index

This is an overview with the first 50 images. Click on the image to get to the respecitve page. If there are more than 50 images then you can select the next overview page at the bottom of this page.


__ contenttail __
Generated by htmlpictures $ver, $today
__ contenthead __ $title
Go to total picture index

$title


__ tail __
content

Generated by htmlpictures $ver, $today
__ head __ $title
content Go to total picture index

$title


__ thumbstop __
__ thumbstart __
 
$file
$file
$txt
__ ende __