#!/usr/bin/perl -w use strict; use List::Util qw(max); use Getopt::Long; ######################################### # # picsite.pl # # Create WWW gallery from JPEG files. # # This script takes all JPEG files in the # current directory, creates scaled down # thumbnail copies and creates a HTML page # for each image as well as an overview # page with all the thumbnails. # # You'll need Perl, jhead (exif reader), the ImageMagick suite and an # external 'ls' command from e.g. Unix or Cygwin. # # http://www.perl.com/ # http://www.imagemagick.org/ # http://www.debian.org/ # http://www.cygwin.com/ # http://www.sentex.net/~mwandel/jhead/ # # (c) 2000-2005 Ralf Hüls # This program is a dirty hack, use it at your own risk ;-) # It may need some tweaking to fit your environment. # Non-commercial use and distribution of this program is permitted. # If you modify this program to create something useful or # interesting, I'd like to hear about it. # ######################################### # # Put name of photographer here # my $name='Ihr Name'; # # Put e-mail address of photographer here # my $mail='name@nodomain.invalid'; # # Put URL of home page here # my $home='http://www.nodomain.invalid/pics.html'; # # Put URL of CSS file here # my $css='http://www.nodomain.invalid/default.css'; # # Put path to auxiluary files here. This should be your name file (see # below) and a 256x256 black image called blackindex.jpg # my $path='/home/husky/web'; # # Put prefix for name file here. This should be a transparent # PNG file called $path/$pre$largest.png with your name tag in a # suitable resolution for $largest to be superimposed over # each image file. # my $pre='rh'; # # Target image size and largest source image size (larger dimension). # (Defaults are for 3504x2336 and 640x427) # my $default=640; my $largest=3504; # ######################################### my $files; my $base; my $tag; my $value; my $exif; my $maxres; my $percent; my $nbase; my $lbase; my $n; my $j; my $k; my $numfiles; my $numidx; my $mogline; my $i; my $image; my $again; my $disclaimer; my @files; my @exif; my %exif; GetOptions("image" => \$image, "disclaimer" => \$disclaimer, "again" => \$again); if ($again) { `rm -f thumb* *.html`; } $files=`ls -1 *.jpg *.JPG`; @files=split "\n",$files; open_index(1); $numfiles=scalar @files; $numidx=int($numfiles / 16); if ( ($numfiles % 16) != 0) { $numidx++; } print "$numfiles $numidx\n"; open H,">index.html"; print H "\n"; print H "\n"; print H "\n"; print H " Photography\n"; print H " \n"; print H " \n"; print H " \n"; print H " \n"; print H " \n"; print H "\n"; print H "\n"; print H "
\n"; print H "Home\n"; for ($j=1;$j <= $numidx;$j++) { open_index($j); print F "Index\n"; for ($i=1;$i <= $numidx;$i++) { $lbase="index$i.html"; print F "[$i]"; } print F "
\n"; print F "\n"; print F "\n"; $i=1; $mogline=""; for ($k=0;$k < 16;$k++) { $n=($j-1)*16+$k; unless (defined $files[$n]) { next; } $base=$files[$n]; $mogline .= " thumb$base"; $mogline =~ s/.JPG/.jpg/; print "$n $base"; undef %exif; @exif=split /\n/,`jhead $base`; foreach (@exif) { $tag=$_; $value=$_; $tag =~ s/^([^:]*):.*$/$1/; $tag =~ s/ *$//; $value =~ s/^[^:]*:(.*)$/$1/; $value =~ s/^ *//; $value =~ s/ *$//; $exif{$tag}=$value; # print "#$tag#$value|\n"; } if ($image) { `jhead -autorot $base`; $maxres=max(split /x/,$exif{'Resolution'}); $maxres =~ s/ *$//; $maxres =~ s/^ *//; unless (-f "$path/$pre$maxres.png") { $percent=$maxres/$largest*100; print "\nNOTE: making $path/$pre$maxres.png ($percent%)\n"; `cp "$path/$pre$largest.png" "$path/$pre$maxres.png"`; `mogrify -geometry $percent% "$path/$pre$maxres.png"`; } `composite -compose over "$path/$pre$maxres.png" $base $base`; $percent=$default/$maxres*100; print "MaxRes: $maxres => $percent%"; if ($percent < 100) { `mogrify -quality 75% -geometry $percent% -unsharp 2x1+1+0 "$base"`; } } print "\n"; $base=~ s/.jpg$//; $base=~ s/.JPG$//; if ($n < (scalar @files)-1) { $nbase=$files[$n+1]; $nbase=~ s/\.jpg$/\.html/; $nbase=~ s/\.JPG$/\.html/; } else { $nbase= "index.html"; } if ($n > 0) { $lbase=$files[$n-1]; $lbase=~ s/\.jpg$/\.html/; $lbase=~ s/\.JPG$/\.html/; } else { $lbase= "index.html"; } `cp "$files[$n]" "thumb$base.jpg"`; `mogrify -geometry 20% "thumb$base.jpg"`; print F "\n"; if ($i==4) { print F "\n"; print F "\n"; $i=0; } $i++; open G,">$base.html"; print G "\n"; print G "\n"; print G "\n"; print G " Photography: $files[$n] \n"; print G " \n"; print G " \n"; print G " \n"; print G " \n"; print G " \n"; print G "\n"; print G "\n"; print G "
\n"; print G "Previous *** \n"; print G "Index *** \n"; print G "[$j] *** \n"; print G "Next

\n"; print G "


\n"; print G "[$files[$n]]\n"; print G "


\n"; print G "

Kamera: $exif{'Camera model'}

\n"; print G "

Brennweite: $exif{'Focal length'}

\n"; print G "

Blende: $exif{'Aperture'}

\n"; print G "

Zeit: $exif{'Exposure time'}

\n"; print G "

Blitz: $exif{'Flash used'}

\n"; print G "


\n"; print G "

\n"; print G "
© 2005 by $name.\n"; print G "
\n"; print G "\n"; print G "\n"; close G; } close_index(); `montage -geometry 64x64+0+0 -tile 4x4 -background black $mogline thumbsindex$j.jpg`; if ($j == $numidx) { `composite -compose over thumbsindex$j.jpg $path/blackindex.jpg thumbsindex$j.jpg`; } print H "

Index $j

\n"; print H "
[index
\n"; } print H "
\n"; print H "\n"; print H "\n"; close H; sub open_index{ open F,">index$_[0].html"; print F "\n"; print F "\n"; print F "\n"; print F " Photography\n"; print F " \n"; print F " \n"; print F " \n"; print F " \n"; print F " \n"; print F "\n"; print F "\n"; print F "
\n"; } sub close_index{ print F "
\n"; print F "
\n"; print F "
\n"; print F "[thumb$base.jpg]\n"; print F "
\n"; print F "
\n"; if ($disclaimer) { print F "Sollten sich auf diesen Seiten Abbildungen von Personen befinden, die mit der Veröffentlichung nicht einverstanden sind, so bitte ich um Mitteilung. Ich werde die Bilder dann umgehend entfernen.

\n"; } print F "
© 2005 by $name.\n"; print F "\n"; print F "\n"; close F; }